use of se.light.assembly64.Support.getObjectMapper in project assembly64fx by freabemania.
the class MetadataService method getStoredMetadata.
private Optional<Metadata> getStoredMetadata(Integer category, String contentId) throws RuntimeException, IOException {
File f = new File(metadataFolder + "/" + buildKey(category, contentId));
if (f.exists()) {
Path path = Paths.get(f.toURI());
BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
long age = System.currentTimeMillis() - attr.creationTime().toMillis();
if (age < METADATA_CACHE_TIME) {
try {
return Optional.of(Support.getObjectMapper().readValue(f, Metadata.class));
} catch (Exception e) {
LOGGER.error("Unable to parse " + f.getAbsolutePath());
FileUtils.deleteQuietly(f);
return Optional.empty();
}
} else {
FileUtils.deleteQuietly(f);
return Optional.empty();
}
} else {
return Optional.empty();
}
}
Aggregations