Search in sources :

Example 1 with AbstractObject

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) {
    }
}
Also used : AbstractObjectWithStringId(org.stepik.api.objects.AbstractObjectWithStringId) Path(java.nio.file.Path) AbstractObject(org.stepik.api.objects.AbstractObject) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 Path (java.nio.file.Path)1 AbstractObject (org.stepik.api.objects.AbstractObject)1 AbstractObjectWithStringId (org.stepik.api.objects.AbstractObjectWithStringId)1