use of org.stepik.api.objects.AbstractObject in project intellij-plugins by StepicOrg.
the class StepikAbstractGetQuery method flushCourse.
private void flushCourse(Object item, Path cachePath) {
String id;
if (item instanceof AbstractObject) {
id = String.valueOf(((AbstractObject) item).getId());
} else if (item instanceof AbstractObjectWithStringId) {
id = ((AbstractObjectWithStringId) item).getId();
} else {
return;
}
Path courseCache = cachePath.resolve(id + JSON_EXTENSION);
try {
Files.createDirectories(courseCache.getParent());
byte[] content = getJsonConverter().toJson(item).getBytes(StandardCharsets.UTF_8);
Files.write(courseCache, content, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (IOException ignored) {
}
}
Aggregations