Search in sources :

Example 1 with Support.getObjectMapper

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();
    }
}
Also used : TargetAndPath(se.light.assembly64.model.TargetAndPath) Path(java.nio.file.Path) File(java.io.File) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) IOException(java.io.IOException)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 TargetAndPath (se.light.assembly64.model.TargetAndPath)1