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.dotcms.publisher.pusher.bundler.LanguageBundler.java

private void copyFileToBundle(File bundleRoot, File messagesDir, Date lastBundleDate)
        throws IOException, DotBundleException, DotDataException, DotSecurityException, DotPublisherException {

    String myFolderUrl = bundleRoot.getPath() + File.separator + "messages";
    File bundleFolderMessages = new File(myFolderUrl);

    for (File lang : FileUtils.listFiles(messagesDir, new String[] { "properties" }, false)) {
        long lastMod = lang.lastModified();
        long startTime = -1;
        if (lastBundleDate != null)
            startTime = lastBundleDate.getTime();
        if (lastMod > startTime) {
            if (!bundleFolderMessages.exists())
                bundleFolderMessages.mkdirs();

            FileUtils.copyFileToDirectory(lang, bundleFolderMessages);
        }/*from ww w. ja  v  a 2 s .  c  o m*/
    }
}

From source file:de.uni.stuttgart.informatik.ToureNPlaner.Net.Handler.SyncCoreLoader.java

private InputStream readCoreFileCached(File coreFile) throws IOException {
    if (getLastModifiedOnServer() > coreFile.lastModified() - 1000 * 60 * 10) {
        return readCoreFileFromNetAndCache();
    }//from www .j  av a  2 s  .  c o  m
    return new FileInputStream(coreFile);
}

From source file:net.sf.jvifm.util.FileComprator.java

public int compare(File file1, File file2) {

    long diff = file1.lastModified() - file2.lastModified();
    int result;/*from   w  w  w. jav  a  2 s  .c  om*/

    if (diff >= 0)
        result = 1;
    else
        result = -1;
    if (isReverse)
        return 0 - result;
    return result;

}

From source file:com.zotoh.core.util.FileUte.java

private static void copyOneFile(File srcFile, File destFile) throws IOException {
    if (destFile.exists()) {

        if (!destFile.isFile()) {
            throw new IOException("\"" + destFile + "\" exists but is not a valid file");
        }/*from  w w w.jav  a 2s.c  o  m*/

        if (!destFile.canWrite()) {
            throw new IOException("Cannot overwrite \"" + destFile + "\"");
        }

    }

    InputStream src = new FileInputStream(srcFile);
    OutputStream out = null;

    try {
        streamToStream(src, out = new FileOutputStream(destFile));
    } finally {
        StreamUte.close(out);
        StreamUte.close(src);
    }

    if (srcFile.length() != destFile.length()) {
        throw new IOException("Failed to copy full contents from '" + srcFile + "' to '" + destFile + "'");
    }

    // preserve the file datetime
    destFile.setLastModified(srcFile.lastModified());
}

From source file:be.vlaanderen.sesam.monitor.internal.ConfigurationServiceImpl.java

@SuppressWarnings("unchecked")
@Scheduled(fixedDelay = SCANTIMEMILLIS)//from  w  w w. j  a  va  2  s. co  m
public void checkConfigurationChange() {
    log.debug("Checking for configuration changes.");
    try {
        File f = new File(configurationFile);
        if (f.isFile()) {
            long l = f.lastModified();
            if (l != lastModified) {
                loadConfiguration();
            }
        } else {
            log.warn("Configuration file not found!");
            monitorService.monitor(Collections.EMPTY_LIST);
        }
    } catch (Exception e) {
        log.warn("Failed checking for configuration changes: " + e.getMessage());
    }
}

From source file:com.aoyetech.fee.commons.utils.FileUtils.java

private static void doCopyFile(final File srcFile, final File destFile, final boolean preserveFileDate)
        throws IOException {
    if (destFile.exists() && destFile.isDirectory()) {
        throw new IOException("Destination '" + destFile + "' exists but is a directory");
    }//from  w  w w .j av a 2s .co  m

    final FileInputStream input = new FileInputStream(srcFile);
    try {
        final FileOutputStream output = new FileOutputStream(destFile);
        try {
            IOUtils.copy(input, output);
        } finally {
            IOUtils.closeQuietly(output);
        }
    } finally {
        IOUtils.closeQuietly(input);
    }

    if (srcFile.length() != destFile.length()) {
        throw new IOException("Failed to copy full contents from '" + srcFile + "' to '" + destFile + "'");
    }
    if (preserveFileDate) {
        destFile.setLastModified(srcFile.lastModified());
    }
}

From source file:net.orpiske.ssps.common.resource.FileResourceExchange.java

@Override
public ResourceInfo info(URI uri) throws ResourceExchangeException {
    File file = new File(uri);

    ResourceInfo ret = new ResourceInfo();

    ret.setSize(FileUtils.sizeOf(file));
    ret.setLastModified(file.lastModified());

    return ret;//w w  w.  ja va2s . c  o  m
}

From source file:it.anyplace.sync.core.cache.FileBlockCache.java

private void runCleanup() {
    if (size > MAX_SIZE) {
        logger.info("starting cleanup of cache directory, initial size = {}",
                FileUtils.byteCountToDisplaySize(size));
        List<File> files = Lists.newArrayList(dir.listFiles());
        Collections.sort(files, Ordering.natural().onResultOf(new Function<File, Long>() {
            @Override//from w  ww .  j ava 2s.  c  o  m
            public Long apply(File input) {
                return input.lastModified();
            }
        }));
        for (File file : Iterables.limit(files, (int) (files.size() * PERC_TO_DELETE))) {
            logger.debug("delete file {}", file);
            FileUtils.deleteQuietly(file);
        }
        size = FileUtils.sizeOfDirectory(dir);
        logger.info("cleanup of cache directory completed, final size = {}",
                FileUtils.byteCountToDisplaySize(size));
    }
}

From source file:com.adaptris.core.http.jetty.JettyHashUserRealmVerifier.java

private Map<String, AccessCredentials> loadUsers() throws IOException {
    File file = new File(filename);
    if (fileLastModified < file.lastModified()) {
        users = loadUsers(PropertyHelper.loadQuietly(file));
        fileLastModified = file.lastModified();
    }/* w  ww  .ja va 2 s .com*/
    return users;
}

From source file:org.bpmscript.js.reload.LibraryFileMonitor.java

/**
 * Checks whether the internal libraries have changed. If they do, publishes
 * out to a queue the list of files that need to be reloaded as a result
 *///from  w w  w . j  a v a 2 s . c om
@SuppressWarnings("unchecked")
protected void checkLibraries() {
    ArrayList<ILibraryToFile> newLibraryToFiles = new ArrayList<ILibraryToFile>();
    libraryAssociationQueue.drainTo(newLibraryToFiles);
    for (ILibraryToFile libraryToFile : newLibraryToFiles) {
        Set set = libraryToFilesMap.get(libraryToFile.getLibrary());
        if (set == null) {
            set = new HashSet<String>();
            libraryToFilesMap.put(libraryToFile.getLibrary(), set);
        }
        set.add(libraryToFile.getFile());
    }
    Iterator iterator = libraryToFilesMap.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry entry = (Entry) iterator.next();
        String library = (String) entry.getKey();
        URL resource = this.getClass().getResource(library);
        if ("file".equals(resource.getProtocol())) {
            String path = resource.getPath();
            File file = new File(path);
            Long newLastModified = file.lastModified();
            Long oldLastModified = libraryToLastModifiedMap.get(library);
            if (oldLastModified != null && !(oldLastModified.equals(newLastModified))) {
                // library has changed, we should go through its files and notify listeners
                // that they need to reload. also, we need to check to see if the files are
                // libraries themselves...
                Collection values = (Collection) entry.getValue();
                for (Iterator valueIterator = values.iterator(); valueIterator.hasNext();) {
                    String value = (String) valueIterator.next();
                    if (libraryToFilesMap.containsKey(value)) {
                        // TODO: here we need to recurse
                    } else {
                        // notify listeners that the file has changed. consider notifying
                        // listeners that the library has changed...
                        libraryChangeQueue.add(new LibraryToFile(library, value));
                    }
                }
                libraryToLastModifiedMap.put(library, newLastModified);
            } else if (oldLastModified == null) {
                libraryToLastModifiedMap.put(library, newLastModified);
            }
        }
    }
}