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.nadmm.airports.tfr.TfrServiceBase.java

protected void cleanupCache(File dir, long maxAge) {
    // Delete all files that are older
    Date now = new Date();
    File[] files = dir.listFiles();
    for (File file : files) {
        long age = now.getTime() - file.lastModified();
        if (age > maxAge) {
            file.delete();/*from w  w  w .  j a  v a  2  s .c  om*/
        }
    }
}

From source file:com.jaeksoft.searchlib.web.PushServlet.java

private static String getPushTargetUrl(Client client, ReplicationItem replicationItem, String cmd,
        File sourceFile)
        throws UnsupportedEncodingException, SearchLibException, MalformedURLException, URISyntaxException {
    String dataPath = replicationItem.getDirectory(client).getAbsolutePath();
    String filePath = sourceFile.getAbsolutePath();
    if (!filePath.startsWith(dataPath))
        throw new SearchLibException("Bad file path " + filePath);
    filePath = filePath.substring(dataPath.length());
    StringBuilder sb = new StringBuilder(replicationItem.getCachedUrl());
    if (cmd != null) {
        sb.append("&cmd=");
        sb.append(cmd);/* w w w.j  a v a2s.co  m*/
    }
    sb.append("&filePath=");
    sb.append(URLEncoder.encode(FileUtils.systemPathToUnix(filePath), "UTF-8"));
    if (sourceFile.isDirectory())
        sb.append("&type=dir");
    else {
        sb.append("&lastModified=" + sourceFile.lastModified());
        sb.append("&length=" + sourceFile.length());
    }
    return sb.toString();
}

From source file:com.aurel.track.util.PluginUtils.java

/**
 * Add class folders and jar files in the lib directories for all plugins.
 * @param tpHome the Genji home directory which includes the plugin directory
 * @return/*from  ww  w.jav a 2  s.  co  m*/
 */
public static void addPluginLocationsToClassPath(String tpHome) {
    File[] pluginDirs = new File[0];
    File directory = new File(tpHome + File.separator + HandleHome.PLUGINS_DIR);
    File resources = new File(tpHome + File.separator + HandleHome.XRESOURCES_DIR);
    File logos = new File(tpHome + File.separator + HandleHome.LOGOS_DIR);
    if (directory != null && directory.exists() && directory.isDirectory()) {
        pluginDirs = directory.listFiles();
    } else {
        return;
    }
    // Expand Genji plugins first
    for (File f : pluginDirs) {
        if (!f.isDirectory() && f.getName().endsWith(".tpx")) {
            String targetDir = f.getAbsolutePath().substring(0, f.getAbsolutePath().length() - 4);
            File td = new File(targetDir);
            if (!td.exists() || (td.lastModified() < f.lastModified()) || !td.isDirectory()) {
                try {
                    unzipFileIntoDirectory(f, directory);
                } catch (Exception e) {
                    LOGGER.error("Problem unzipping archive: " + e.getMessage());
                }
            }
        }
    }
    pluginDirs = directory.listFiles();
    // Now process the directories in <TRACKPLUS_HOME>/plugins
    ArrayList<File> files = new ArrayList<File>();
    ArrayList<File> jsdirs = new ArrayList<File>();
    ArrayList<String> bundles = new ArrayList<String>();

    for (File f : pluginDirs) {
        if (f != null && f.exists() && f.isDirectory()) {
            files.add(f);
            File classes = new File(f.getAbsolutePath() + File.separator + "classes");
            if (classes != null && classes.exists() && classes.isDirectory()) {
                files.add(classes);
            }
            File libs = new File(f.getAbsolutePath() + File.separator + "lib");
            File[] jars = new File[0];
            if (libs != null && libs.exists() && libs.isDirectory()) {
                jars = libs.listFiles();
            }

            for (File fj : jars) {
                if (fj.exists() && !fj.isDirectory() && fj.getAbsolutePath().endsWith(".jar")) {
                    files.add(fj);
                }
            }

            File conf = new File(f.getAbsolutePath() + File.separator + "conf");
            if (conf != null && conf.exists() && conf.isDirectory()) {
                files.add(conf);
            }

            File js = new File(f.getAbsolutePath() + File.separator + "js");
            if (js != null && js.exists() && js.isDirectory()) {
                jsdirs.add(f);
            }

            bundles.add("resources." + f.getName());
        }
    }
    URLClassLoader sysloader = null;
    try {
        sysloader = (URLClassLoader) StartServlet.class.getClassLoader();

        Class sysclass = URLClassLoader.class;
        for (File file : files) {
            try {
                LOGGER.info("Adding " + file.getAbsolutePath() + " to classpath.");
                Method method = sysclass.getDeclaredMethod("addURL", parameters);
                method.setAccessible(true);
                method.invoke(sysloader, new Object[] { file.toURI().toURL() });
            } catch (Exception t) {
                LOGGER.error(ExceptionUtils.getStackTrace(t));
            }
        }

        try {
            LOGGER.info("Trying to add " + resources.getAbsolutePath() + " to classpath.");
            Method method = sysclass.getDeclaredMethod("addURL", parameters);
            method.setAccessible(true);
            method.invoke(sysloader, new Object[] { resources.toURI().toURL() });
        } catch (Exception t) {
            LOGGER.info("No custom resources found, okay.");
        }

        try {
            LOGGER.info("Trying to add " + logos.getAbsolutePath() + " to classpath.");
            Method method = sysclass.getDeclaredMethod("addURL", parameters);
            method.setAccessible(true);
            method.invoke(sysloader, new Object[] { logos.toURI().toURL() });
        } catch (Exception t) {
            LOGGER.info("No custom logos found, okay.");
        }
    } catch (Exception e) {
        LOGGER.warn(
                "URLClassloader not supported. You have to add your plugins to the Java classpath manually");
    }
    setJavaScriptExtensionDirs(jsdirs);
    setBundles(bundles);

    return;
}

From source file:com.puffywhiteshare.CloudBucket.java

public void add(File f) throws FileNotFoundException, IOException {
    Date lastModified = new Date(f.lastModified());
    String md5 = "AAAA AAAA AAAA AAAA"; //DigestUtils.md5Hex(new FileInputStream(f));
    String path = f.getAbsolutePath();
    size += f.length();// www . j a  v  a  2s . c o m
    count++;
    CloudObject obj = new CloudObject(path, md5, lastModified);
    logger.info("CloudObject created: path[" + path + "]:md5[" + md5 + "]:last[" + lastModified + "]");
    objects.add(obj);

}

From source file:com.kylinolap.common.persistence.FileResourceStore.java

@Override
protected long getResourceTimestampImpl(String resPath) throws IOException {
    File f = file(resPath);
    return f.lastModified();
}

From source file:de.clusteval.run.result.ParameterOptimizationResult.java

/**
 * @param repository//w  ww  .  ja v  a  2  s  .c o m
 * @param run
 * @param method
 * @param completeFile
 * @param parseClusterings
 * @param storeClusterings
 * @param register
 *            A boolean indicating whether to register the parsed runresult.
 * @return The parameter optimization run result parsed from the given
 *         runresult folder.
 * @throws RegisterException
 * @throws RunResultParseException
 */
public static ParameterOptimizationResult parseFromRunResultCompleteFile(Repository repository,
        ParameterOptimizationRun run, ParameterOptimizationMethod method, File completeFile,
        final boolean parseClusterings, final boolean storeClusterings, final boolean register)
        throws RegisterException, RunResultParseException {
    ParameterOptimizationResult result = null;
    if (completeFile.exists()) {
        result = new ParameterOptimizationResult(repository, false, completeFile.lastModified(), completeFile,
                completeFile.getParentFile().getParentFile().getName(), run, method, parseClusterings,
                storeClusterings);

        if (register) {
            result.loadIntoMemory();
            try {
                result.register();
            } finally {
                result.unloadFromMemory();
            }
        }
    }
    return result;
}

From source file:com.frostwire.platform.DefaultFileSystem.java

@Override
public long lastModified(File file) {
    return file.lastModified();
}

From source file:net.sf.jvifm.model.filter.AgeFileFilter2.java

public boolean accept(File file) {
    long threshold = System.currentTimeMillis() - cutoff;
    long modifiedTime = file.lastModified();

    if (flag == EQ) {
        return (modifiedTime == threshold);

    } else if (flag == GT) {
        return (modifiedTime < threshold);

    } else if (flag == LT) {
        return (modifiedTime > threshold);
    } else {//ww w. j  ava2  s .c o m
        return false;
    }

}

From source file:com.econcept.entity.UserFile.java

public UserFile(File pFile) {
    mFileName = pFile.getName();
    mLastModified = Long.toString(pFile.lastModified());
    mFileSize = Long.toString(pFile.length());
}

From source file:net.sbfmc.modules.anticheat.conf.AnticheatReportsNicksConf.java

@Override
public void initConf() throws IOException {
    confFolder = new File(SBFPlugin.getPlugin().getDataFolder(), "anticheat_reports");

    if (confFolder.exists() && confFolder.length() / 1024 / 1024 > 256) {
        File[] files = confFolder.listFiles();
        Arrays.sort(files, new Comparator<File>() {
            @Override/*from  w w  w. j  a v  a2 s. com*/
            public int compare(File o1, File o2) {
                return (int) (o1.lastModified() - o2.lastModified());
            }
        });
        ArrayUtils.reverse(files);
        for (File file : files) {
            if (confFolder.length() / 1024 / 1024 < 256) {
                break;
            }
            file.delete();
        }
    }

    createConf();
}