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:de.wpsverlinden.dupfind.HashCalculator.java

public void calculateHashes() {
    outputPrinter.print("Calculating hashes ...");
    entries.parallelStream().filter((e) -> {
        File file = new File(userDir + e.getPath());
        return (file.exists() && file.isFile() && e.getHash().isEmpty()
                || e.getLastModified() < file.lastModified());
    }).forEach((e) -> {/*from w w  w  .  j  av  a  2s .  co  m*/
        calc(e);
        outputPrinter.print(".");
    });
    outputPrinter.println(" done.");
}

From source file:jobhunter.persistence.Persistence.java

private Boolean wasModified(final File file) {
    if (this.lastModification != file.lastModified())
        return true;

    try (InputStream in = new FileInputStream(file)) {
        return Arrays.equals(this.md5sum, DigestUtils.md5(in));
    } catch (IOException e) {
        l.error("Failed to read MD5 checksum from {}", file.toString(), e);
    }//from  w  w w .  j  ava2  s  .  c  o m

    return false;
}

From source file:com.aegiswallet.tasks.GetCurrencyInfoTask.java

public boolean shouldRefreshFile(String fname) {
    File file = context.getApplicationContext().getFileStreamPath(fname);

    long msBetweenDates = new Date().getTime() - file.lastModified();
    long minutes = TimeUnit.MILLISECONDS.toMinutes(msBetweenDates);
    if (minutes > 15)
        return true;
    else/*  w  w  w.  jav a 2 s .  c om*/
        return false;
}

From source file:com.virtualparadigm.packman.processor.JPackageManagerOld.java

public static boolean configure(File tempDir, Configuration configuration) {
    logger.info("PackageManager::configure()");
    boolean status = true;
    if (tempDir != null && configuration != null && !configuration.isEmpty()) {
        ST stringTemplate = null;/*from   w w  w.  j  a v a 2  s.  c  om*/
        String templateContent = null;
        long lastModified;

        Collection<File> patchFiles = FileUtils.listFiles(
                new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.PATCH_DIR_NAME + "/"
                        + JPackageManagerOld.PATCH_FILES_DIR_NAME),
                TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY);

        if (patchFiles != null) {
            for (File pfile : patchFiles) {
                logger.debug("  processing patch fileset file: " + pfile.getAbsolutePath());
                try {
                    lastModified = pfile.lastModified();
                    templateContent = FileUtils.readFileToString(pfile);
                    templateContent = templateContent.replace("${", "\\${");
                    templateContent = templateContent.replace("@", "\\@");
                    stringTemplate = new ST(JPackageManagerOld.ST_GROUP, templateContent);
                    //                       stringTemplate = new ST(FileUtils.readFileToString(pfile));
                    JPackageManagerOld.addTemplateAttributes(stringTemplate, configuration);
                    templateContent = stringTemplate.render();
                    templateContent = templateContent.replace("\\${", "${");
                    templateContent = templateContent.replace("\\@", "@");
                    FileUtils.writeStringToFile(pfile, templateContent);
                    pfile.setLastModified(lastModified);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        Collection<File> scriptFiles = FileUtils.listFiles(
                new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.AUTORUN_DIR_NAME),
                TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY);

        if (scriptFiles != null) {
            for (File scriptfile : scriptFiles) {
                logger.debug("  processing script file: " + scriptfile.getAbsolutePath());
                try {
                    lastModified = scriptfile.lastModified();
                    templateContent = FileUtils.readFileToString(scriptfile);
                    templateContent = templateContent.replace("${", "\\${");
                    templateContent = templateContent.replace("@", "\\@");
                    stringTemplate = new ST(JPackageManagerOld.ST_GROUP, templateContent);
                    //                       stringTemplate = new ST(FileUtils.readFileToString(pfile));
                    JPackageManagerOld.addTemplateAttributes(stringTemplate, configuration);
                    templateContent = stringTemplate.render();
                    templateContent = templateContent.replace("\\${", "${");
                    templateContent = templateContent.replace("\\@", "@");
                    FileUtils.writeStringToFile(scriptfile, templateContent);
                    scriptfile.setLastModified(lastModified);

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return status;
}

From source file:SecuritySupport.java

long getLastModified(File f) {
    return f.lastModified();
}

From source file:com.thoughtworks.go.agent.launcher.LockfileTest.java

@Test
public void shouldReturnFalseIfLockFileAlreadyExists() throws IOException {
    File mockfile = mock(File.class);
    Lockfile lockfile = new Lockfile(mockfile);
    when(mockfile.exists()).thenReturn(true);
    when(mockfile.lastModified()).thenReturn(System.currentTimeMillis());
    assertThat(lockfile.tryLock(), is(false));
    verify(mockfile).exists();/*from w w  w.  j a  v a2 s  .  c o  m*/
}

From source file:io.dstream.tez.utils.ClassPathUtils.java

/**
 *
 * @param source// w  w  w .j  a  va  2 s . c  om
 * @param lengthOfOriginalPath
 * @param target
 * @throws IOException
 */
private static void add(File source, int lengthOfOriginalPath, JarOutputStream target) throws IOException {
    BufferedInputStream in = null;
    try {
        String path = source.getAbsolutePath();
        path = path.substring(lengthOfOriginalPath);

        if (source.isDirectory()) {
            String name = path.replace("\\", "/");
            if (!name.isEmpty()) {
                if (!name.endsWith("/")) {
                    name += "/";
                }
                JarEntry entry = new JarEntry(name.substring(1)); // avoiding absolute path warning
                target.putNextEntry(entry);
                target.closeEntry();
            }

            for (File nestedFile : source.listFiles()) {
                add(nestedFile, lengthOfOriginalPath, target);
            }

            return;
        }

        JarEntry entry = new JarEntry(path.replace("\\", "/").substring(1)); // avoiding absolute path warning
        entry.setTime(source.lastModified());
        try {
            target.putNextEntry(entry);
            in = new BufferedInputStream(new FileInputStream(source));

            byte[] buffer = new byte[1024];
            while (true) {
                int count = in.read(buffer);
                if (count == -1) {
                    break;
                }
                target.write(buffer, 0, count);
            }
            target.closeEntry();
        } catch (Exception e) {
            String message = e.getMessage();
            if (message != null) {
                if (!message.toLowerCase().contains("duplicate")) {
                    throw new IllegalStateException(e);
                }
                logger.warn(message);
            } else {
                throw new IllegalStateException(e);
            }
        }
    } finally {
        if (in != null)
            in.close();
    }
}

From source file:it.tidalwave.northernwind.frontend.filesystem.impl.ResourceFileNetBeansPlatform.java

@Override
@Nonnull/*from w w  w. ja  v  a  2s  . c om*/
public ZonedDateTime getLatestModificationTime() {
    // See NW-154
    final File file = toFile();

    final long millis = (file != null) ? file.lastModified() : delegate.lastModified().getTime();
    return Instant.ofEpochMilli(millis).atZone(ZoneId.of("GMT"));
}

From source file:com.moss.error_reporting.server.ReportingServiceImpl.java

public List<ErrorReportSummary> listReportSummaries() {
    List<ErrorReportSummary> summaries = new LinkedList<ErrorReportSummary>();

    String[] namesList = documentRepository.getDocumentsDirLocation().list();
    for (String name : namesList) {
        try {//from   ww w  .j  a va2 s . co  m
            ReportId id = new ReportId(name);
            log.debug("version 0.0.3");
            log.debug("found report with id: " + name);
            //            ErrorReport report = getReport(new ReportId(name));

            File file = documentRepository.path(id.getUuid());

            Instant lastModified = new Instant(file.lastModified());

            summaries.add(new ErrorReportSummary(id, lastModified));

        } catch (Exception ex) {
            log.info(ex.getStackTrace());
        }
    }

    return summaries;
}

From source file:jenkins.plugins.itemstorage.s3.Downloads.java

public void startDownload(TransferManager manager, File base, String pathPrefix, S3ObjectSummary summary)
        throws AmazonServiceException, IOException {
    // calculate target file name
    File targetFile = FileUtils.getFile(base, summary.getKey().substring(pathPrefix.length() + 1));

    // if target file exists, only download it if newer
    if (targetFile.lastModified() < summary.getLastModified().getTime()) {
        // ensure directory above file exists
        FileUtils.forceMkdir(targetFile.getParentFile());

        // Start the download
        Download download = manager.download(summary.getBucketName(), summary.getKey(), targetFile);

        // Keep for later
        startedDownloads.add(new Memo(download, targetFile, summary.getLastModified().getTime()));
    }//from   ww w  . ja va  2s  . co m
}