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:dk.dr.radio.net.Diverse.java

    ldreEnd(File mappe, long tidsstempel) {
  int antalByteDerBlevSlettet = 0;
  int antalFilerDerBlevSlettet = 0;
  File[] files = mappe.listFiles();
  if (files != null) {
    for (File file : files) {
      if (file.lastModified() < tidsstempel) {
        antalByteDerBlevSlettet += file.length();
        antalFilerDerBlevSlettet++;/*w  ww  . ja va2s . c o  m*/
        file.delete();
      }
    }
  }
  Log.d("sletFilerldreEnd: " + mappe.getName() + ": " + antalFilerDerBlevSlettet + " filer blev slettet, og " + antalByteDerBlevSlettet / 1000 + " kb frigivet");
  return antalByteDerBlevSlettet;
}

From source file:com.fanniemae.ezpie.data.jdbcproviders.JdbcProvider.java

public String getJarFilename(String jdbcJarFilename) {
    if ((jdbcJarFilename != null) && !jdbcJarFilename.isEmpty()) {
        return jdbcJarFilename;
    }/*from   w  w  w .  ja v  a  2  s  .  c o m*/

    File dir = new File(_session.getJarPath());
    FilenameFilter filter = new RegexFileFilter(_urlRegex);
    File[] files = dir.listFiles(filter);
    if ((files == null) || (files.length == 0)) {
        throw new PieException(String.format("No matching JDBC driver found in %s.", dir.getAbsolutePath()));
    }

    File latestDriver = files[0];
    for (int i = 0; i < files.length; i++) {
        if (latestDriver.lastModified() < files[i].lastModified()) {
            latestDriver = files[i];
        }
    }

    return latestDriver.getAbsolutePath();
}

From source file:com.alibaba.zonda.logger.server.LogMonitor.java

private void refresh() {

    // select one log file randomly
    // maybe the first time
    if (null == logFile) {
        File[] logs = baseDir.listFiles(fileFilter);
        if (null != logs && logs.length > 0) {
            try {
                this.logFile = logs[0];
                this.stream = new BufferedInputStream(new FileInputStream(logs[0]), 8192);
            } catch (FileNotFoundException e) {
                logger.error("log file not exists, try later");
                return;
            }/*from  ww w  . jav a 2s  .  co  m*/
        }
    }

    long nowModified = logFile.lastModified();
    if (nowModified < modifyTime) {
        logger.debug("current log file: {} is running, modify time: {}", logFile, nowModified);
        return;
    } else {
        logger.debug("current log file: {} is silent, refresh directory", logFile);
        logger.debug("current log modify time: {}", this.modifyTime);
        logger.debug("last modify time: {}", nowModified);
        logger.debug("last line number: {}", lineNo);
        this.modifyTime = nowModified;
    }

    try {
        File[] logs = baseDir.listFiles(fileFilter);
        if (null != logs) { // select the latest modified xxx.tmp log file
            for (File log : logs) {
                if ((log.lastModified() > modifyTime) && !(log.getName().equals(logFile.getName()))) {
                    logger.info("using new log file: {}", log.getName());
                    if (null != this.stream) {
                        this.stream.close();
                    }

                    this.logFile = log;
                    this.stream = new BufferedInputStream(new FileInputStream(log), 8192);
                    this.lineNo = 0;
                }
            }
        }
    } catch (Exception e) {
        logger.error("list log file failed, message: {}", e);
    }
}

From source file:com.microsoft.alm.plugin.idea.common.setup.WindowsStartup.java

/**
 * Check if registry keys exist and if the cmd file the key contains matches the latest cmd file
 *
 * @param newCmd//w  ww . j  a v a  2  s.c om
 * @return if keys exists or not
 */
protected static boolean doesKeyNeedUpdated(final File newCmd) throws IOException {
    try {
        final String existingKey = Advapi32Util.registryGetStringValue(WinReg.HKEY_CLASSES_ROOT, VSOI_KEY,
                StringUtils.EMPTY);
        final File existingCmd = new File(existingKey.replace("\"%1\"", "").trim());
        if (!existingCmd.exists()) {
            logger.debug("The registry key needs updated because the old key cmd file doesn't exist.");
            return true;
        }

        if (existingCmd.getPath().equalsIgnoreCase(newCmd.getPath())
                || FileUtils.contentEquals(existingCmd, newCmd)) {
            logger.debug("The registry key does not need updated because {}",
                    existingCmd.getPath().equalsIgnoreCase(newCmd.getPath()) ? "the file paths are the same"
                            : "the contents of the files are the same.");
            return false;
        }

        // use the newest cmd file so update if existing cmd file is older
        // TODO: version cmd file if we continually iterate on it so we chose the correct file more reliably
        logger.debug("The existing cmd file is {} old and the the cmd file is {} old",
                existingCmd.lastModified(), newCmd.lastModified());
        return existingCmd.lastModified() < newCmd.lastModified() ? true : false;
    } catch (Win32Exception e) {
        // Error occurred reading the registry (possible key doesn't exist or is empty) so update just to be safe
        logger.debug("There was an issue reading the registry so updating the key to be safe.");
        return true;
    }
}

From source file:edu.lternet.pasta.auditmanager.AuditCleaner.java

/**
 * Removes any audit records XML file that is older than the specified 
 * time-to-live (ttl).//from   www  . jav a  2 s  . c  o  m
 * 
 * @param ttl
 *            The time-to-live value in milliseconds.
 */
public void doClean(Long ttl) {
    File tmpDir = new File(this.tmpDir);
    String[] ext = { "xml" };
    Long time = new Date().getTime();
    Long lastModified = null;

    Collection<File> files = FileUtils.listFiles(tmpDir, ext, false);

    for (File file : files) {
        if (file != null && file.exists()) {
            lastModified = file.lastModified();
            // Remove file if older than the ttl
            if (lastModified + ttl <= time) {
                try {
                    FileUtils.forceDelete(file);
                } catch (IOException e) {
                    logger.error(e.getMessage());
                    e.printStackTrace();
                }
            }
        }
    }
}

From source file:it.grid.storm.authz.sa.conf.FileAuthzDBReader.java

public long getLastParsed(String dbFileName) throws AuthzDBReaderException {

    String authzDBFileName = getAbsoluteAuthzDBName(dbFileName);
    File authzFile = new File(authzDBFileName);
    authzFile.lastModified();
    return 0;//from  w  w  w. ja v  a  2 s .co  m
}

From source file:org.xmlactions.common.io.ResourceUtils.java

/**
 * copy a file.//  w w w .jav a 2  s. c  o m
 * 
 * @param sourceFile
 *            is the file we want to copy.
 * @param destFile
 *            is the destination file to copy to.
 */
public static void copyFile(File sourceFile, File destFile) throws Exception {

    try {
        FileInputStream fis = new FileInputStream(sourceFile);
        FileOutputStream fos = new FileOutputStream(destFile);
        copyFileStreams(fis, fos);
    } catch (Exception ex) {
        throw new Exception("Unable to copy file '" + sourceFile.getAbsolutePath() + "' to '"
                + destFile.getAbsolutePath() + "'", ex);
    }
    if (destFile.setLastModified(sourceFile.lastModified()) == false) {
        throw new Exception("Unable to change lastModified time on file:" + destFile.getAbsolutePath()
                + "\nfrom:" + DateTime.getDate(destFile.lastModified(), "dd-MO-yy hh:mm:ss") + " to:"
                + DateTime.getDate(sourceFile.lastModified(), "dd-MO-yy hh:mm:ss"));
    }
}

From source file:biz.gabrys.maven.plugins.directory.content.TransformListMojo.java

private boolean isTransformationRequired(final Collection<File> files) {
    if (force || !outputFile.exists()) {
        return true;
    }//from   ww w.ja  v a2s.  c  o  m
    for (final File file : files) {
        if (file.lastModified() >= outputFile.lastModified()) {
            return true;
        }
    }
    return false;
}

From source file:ca.simplegames.micro.viewers.velocity.MicroResourceLoader.java

/**
 * Return get the last modified time for the resource.
 *
 * @param resource The Resource/*from   www.ja  v  a2s . co  m*/
 * @return The last modified time
 */

public long getLastModified(Resource resource) {
    if (VM_GLOBAL_LIBRARY.equals(resource.getName())) {
        return -1;
    }

    try {
        File file = new File(resource.getName());
        return file.lastModified();
    } catch (Exception e) {
        e.printStackTrace();
        return -1;
    }
}

From source file:net.gcolin.simplerepo.test.RepoCacheTest.java

@Test
public void test() throws Exception {
    Server server1 = createServer(18080, "server1");
    Server server2 = createServer(18081, "server2");
    try {//from w  ww.ja  va 2 s .  c  o m
        addRepository("server1", "test", null);
        addRepository("server2", "test", "http://localhost:18080/simple-repo/repository/test/");

        File file = new File("target/reposerver1/test/foo/bar.txt");
        file.getParentFile().mkdirs();
        FileUtils.write(file, "hello", "utf-8");
        Assert.assertEquals("hello",
                getContent("http://localhost:18081/simple-repo/repository/test/foo/bar.txt", 0));
        Thread.sleep(1000);
        FileUtils.write(file, "world", "utf-8");
        Assert.assertEquals("hello",
                getContent("http://localhost:18081/simple-repo/repository/test/foo/bar.txt", 0));

        setArtifactMaxAge("server2", "test", 100);
        Thread.sleep(1000);
        Assert.assertEquals("world",
                getContent("http://localhost:18081/simple-repo/repository/test/foo/bar.txt", 0));
        File file2 = new File("target/reposerver2/test/foo/bar.txt");
        long lastUpdate = file2.lastModified();
        Thread.sleep(1000);
        Assert.assertEquals("world",
                getContent("http://localhost:18081/simple-repo/repository/test/foo/bar.txt", 0));
        Assert.assertEquals(lastUpdate, file2.lastModified());

        lastUpdate = file2.lastModified();
        FileUtils.write(file2, "world2", "utf-8");
        Thread.sleep(1000);
        Assert.assertEquals("world2",
                getContent("http://localhost:18081/simple-repo/repository/test/foo/bar.txt", lastUpdate));
    } finally {
        server1.stop();
        server2.stop();
    }
}