Example usage for java.io File lastModified

List of usage examples for java.io File lastModified

Introduction

In this page you can find the example usage for java.io File lastModified.

Prototype

public long lastModified() 

Source Link

Document

Returns the time that the file denoted by this abstract pathname was last modified.

Usage

From source file:com.unidev.polycms.hateoas.controller.StorageIndexController.java

@GetMapping(value = "/storage/{storage}/metadata", produces = MediaType.APPLICATION_JSON_VALUE)
public ResourceSupport metadata(@PathVariable("storage") String storage) {
    if (!polyCore.existTenant(storage)) {
        LOG.warn("Not found storage {}", storage);
        throw new StorageNotFoundException("Storage " + storage + " not found");
    }/* w ww  . ja va2s  . co m*/
    BasicPoly metadata = new BasicPoly();
    File flatFile = polyCore.fetchFlatFile(storage);
    File sqliteFile = polyCore.fetchSqliteFile(storage);

    if (flatFile != null && flatFile.exists()) {
        metadata.put(LAST_PROPERTIES_CHANGE_KEY, flatFile.lastModified());
    }
    if (sqliteFile != null && sqliteFile.exists()) {
        metadata.put(LAST_STORAGE_CHANGE_KEY, flatFile.lastModified());
    }
    return hateoasResponse().data(metadata);
}

From source file:org.codetrack.database.file.FileDatabaseConnectionTest.java

@Test
public void testOpen() throws Exception {

    databaseManager.uses(databaseParameters.getName());
    DatabaseConnection databaseConnection = databaseManager.getActiveDatabaseConnection();

    assertNotNull(databaseConnection);/*from  w  w w . j a  va 2s  .c  o  m*/

    assertTrue(databaseConnection instanceof FileDatabaseConnection);

    FileDatabaseConnection fileDatabaseConnection = (FileDatabaseConnection) databaseConnection;

    assertNotNull(fileDatabaseConnection.getFileName());

    String expectedFileName = fileDatabaseConnection.getDatabaseParameters().getPath()
            + FileTestConfiguration.FILE_SEPARATOR + "databases" + FileTestConfiguration.FILE_SEPARATOR
            + fileDatabaseConnection.getDatabaseParameters().getName()
            + FileDatabaseConnection.DATABASE_EXTENSION;

    assertNotNull(fileDatabaseConnection.getFileName());
    assertEquals(fileDatabaseConnection.getFileName(), expectedFileName);

    // Testing load without file
    fileDatabaseConnection.load();

    Database database = fileDatabaseConnection.getDatabase();
    assertNotNull(database);
    assertEquals(fileDatabaseConnection.getDatabaseParameters().getName(), database.getName());

    // Create and Add new project
    database.addProject(FileProject.newBuilder().id(FileTestConfiguration.PROJECT_ID)
            .name(FileTestConfiguration.PROJECT_NAME)
            .description(FileTestConfiguration.PROJECT_TEXT_DESCRIPTION).build());

    // Testing first time save
    fileDatabaseConnection.save();

    File firstFile = new File(expectedFileName);
    assertTrue(firstFile.exists());
    assertTrue(firstFile.isFile());

    long firstLength = firstFile.length();
    long firstModified = firstFile.lastModified();

    database.setName(FileTestConfiguration.DATABASE_TEXT_NAME_MODIFIED);
    database.selectProject(FileTestConfiguration.PROJECT_ID)
            .setDescription(FileTestConfiguration.PROJECT_TEXT_DESCRIPTION_MODIFIED);
    fileDatabaseConnection.save();

    File savedFile = new File(expectedFileName);
    assertTrue(savedFile.exists());
    assertTrue(savedFile.isFile());

    fileDatabaseConnection.close();

}

From source file:com.ethlo.geodata.util.ResourceUtil.java

private Entry<Date, File> downloadIfNewer(DataType dataType, Resource resource, CheckedFunction<Path, Path> fun)
        throws IOException {
    publisher.publishEvent(new DataLoadedEvent(this, dataType, Operation.DOWNLOAD, 0, 1));
    final String alias = dataType.name().toLowerCase();
    final File tmpDownloadedFile = new File(tmpDir, alias);
    final Date remoteLastModified = new Date(resource.lastModified());
    final long localLastModified = tmpDownloadedFile.exists() ? tmpDownloadedFile.lastModified() : -2;
    logger.info(//w  w w.j  a  va2 s.  c o  m
            "Local file for alias {}" + "\nPath: {}" + "\nExists: {}" + "\nLocal last-modified: {} "
                    + "\nRemote last modified: {}",
            alias, tmpDownloadedFile.getAbsolutePath(), tmpDownloadedFile.exists(),
            formatDate(localLastModified), formatDate(remoteLastModified.getTime()));

    if (!tmpDownloadedFile.exists() || remoteLastModified.getTime() > localLastModified) {
        logger.info("Downloading {}", resource.getURL());
        Files.copy(resource.getInputStream(), tmpDownloadedFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
        logger.info("Download complete");
    }

    final Path preppedFile = fun.apply(tmpDownloadedFile.toPath());
    Files.setLastModifiedTime(tmpDownloadedFile.toPath(), FileTime.fromMillis(remoteLastModified.getTime()));
    Files.setLastModifiedTime(preppedFile, FileTime.fromMillis(remoteLastModified.getTime()));
    publisher.publishEvent(new DataLoadedEvent(this, dataType, Operation.DOWNLOAD, 1, 1));
    return new AbstractMap.SimpleEntry<>(new Date(remoteLastModified.getTime()), preppedFile.toFile());
}

From source file:com.norconex.jef4.status.FileJobStatusStore.java

@Override
public long touch(String suiteName, String jobId) throws IOException {
    File file = getStatusFile(suiteName, jobId);
    FileUtils.touch(file);/*from w  w w.j av  a  2 s  . c om*/
    return file.lastModified();
}

From source file:com.netxforge.oss2.config.DefaultCapsdConfigManager.java

/**
 * <p>update</p>//from   w  ww .  ja  v  a 2  s.  co  m
 *
 * @throws java.io.IOException if any.
 * @throws java.io.FileNotFoundException if any.
 * @throws org.exolab.castor.xml.MarshalException if any.
 * @throws org.exolab.castor.xml.ValidationException if any.
 */
protected synchronized void update()
        throws IOException, FileNotFoundException, MarshalException, ValidationException {
    File configFile = ConfigFileConstants.getFile(ConfigFileConstants.CAPSD_CONFIG_FILE_NAME);

    log().debug("Checking to see if capsd configuration should be reloaded from " + configFile);

    if (m_currentVersion < configFile.lastModified()) {
        log().debug("Reloading capsd configuration file");

        long lastModified = configFile.lastModified();

        InputStream is = null;
        try {
            is = new FileInputStream(configFile);
            loadXml(is);
        } finally {
            if (is != null) {
                IOUtils.closeQuietly(is);
            }
        }

        // Update currentVersion after we have successfully reloaded
        m_currentVersion = lastModified;

        log().info("Reloaded capsd configuration file");
    }
}

From source file:com.t3.image.ThumbnailManager.java

private BufferedImage getCachedThumbnail(File file) {

    File thumbnailFile = getThumbnailFile(file);

    if (!thumbnailFile.exists()) {
        return null;
    }//from  w  w  w .  j a  v  a2s.c o m

    try {
        // Check that it hasn't changed on disk
        if (file.lastModified() > thumbnailFile.lastModified()) {
            return null;
        }

        // Get the thumbnail
        BufferedImage thumbnail = ImageIO.read(thumbnailFile);

        // Check that we have the size we want
        if (thumbnail.getWidth() != thumbnailSize.width && thumbnail.getHeight() != thumbnailSize.height) {
            return null;
        }

        return thumbnail;
    } catch (IOException ioe) {
        return null;
    }
}

From source file:edu.unc.lib.dl.services.BatchIngestQueue.java

public File[] getFailedDirectories() {
    File[] batchDirs = this.failedDirectory.listFiles(new FileFilter() {
        @Override/*from w  w  w. j  a v a  2  s .  co m*/
        public boolean accept(File arg0) {
            return arg0.isDirectory();
        }
    });
    if (batchDirs != null) {
        Arrays.sort(batchDirs, new Comparator<File>() {
            @Override
            public int compare(File o1, File o2) {
                if (o1 == null || o2 == null)
                    return 0;
                return (int) (o1.lastModified() - o2.lastModified());
            }
        });
        return batchDirs;
    } else {
        return new File[] {};
    }
}

From source file:edu.unc.lib.dl.services.BatchIngestQueue.java

/**
 * @return/* ww w . java  2  s . co  m*/
 */
public File[] getFinishedDirectories() {
    File[] batchDirs = this.finishedDirectory.listFiles(new FileFilter() {
        @Override
        public boolean accept(File arg0) {
            return arg0.isDirectory();
        }
    });
    if (batchDirs != null) {
        Arrays.sort(batchDirs, new Comparator<File>() {
            @Override
            public int compare(File o1, File o2) {
                if (o1 == null || o2 == null)
                    return 0;
                return (int) (o1.lastModified() - o2.lastModified());
            }
        });
    } else {
        return new File[] {};
    }
    return batchDirs;
}

From source file:PVGraph.java

public static boolean loadProperties() {
    File propsFile = new File("pvgraph.properties");
    if (props == null || propsFile.lastModified() > propsLastLoadedAt) {
        propsLastLoadedAt = System.currentTimeMillis();
        props = new Properties(System.getProperties());
        if (propsFile.canRead()) {
            try {
                FileInputStream propsInputStream = new FileInputStream(propsFile);
                props.load(propsInputStream);
                propsInputStream.close();
            } catch (IOException ioe) {
                // relax
            }//from www  . java 2  s .  com
        }
        return true;
    }
    return false;
}

From source file:org.jtheque.movies.persistence.od.MovieImplTest.java

@Test
public void getLastModifiedData() {
    assertNull(movie.getFileLastModifiedDate());

    File f = FileUtils.getAnExistingFile();

    movie.setFile(f.getAbsolutePath());/*from  w  w  w  .  ja  va2 s .c  om*/

    assertEquals(f.lastModified(), movie.getFileLastModifiedDate().getTime());
}