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:coral.RessyncServable.java

/**
 * check if the file needs to be updated, if yes, send out a get request
 *///from w ww .j av  a2  s . c  om
@Override
public void process(Message cmd, BlockingQueue<Message> outQueue) {
    if (cmd == null) {
        //         queue = outQueue;
    } else {

        String filename = cmd.getContent();

        if (logger.isDebugEnabled()) {
            logger.debug("check  " + filename + " - " + cmd.getFullContent());
        }

        Map<String, String> q = CoralUtils.urlToMap(cmd.getFullContent());

        if (logger.isDebugEnabled()) {
            logger.debug("check map " + q.toString());
        }

        final File file = new File(res, filename);

        logger.debug("check file " + file.getAbsolutePath());

        boolean request = false;
        if (file.exists()) {
            long version = file.lastModified();

            long expectedVersion = Long.parseLong(q.get("version"));

            if (expectedVersion > version) {
                request = true;
            }
        } else {
            request = true;
        }

        if (request) {
            outQueue.add(new Message(q.get("synccmd"), new byte[] {}));
        }
    }
}

From source file:de.matzefratze123.heavyspleef.core.i18n.YMLControl.java

@Override
public boolean needsReload(String baseName, Locale locale, String format, ClassLoader loader,
        ResourceBundle bundle, long loadTime) {
    boolean reload;

    if (format.equals(YML_FORMAT)) {
        String bundleName = toBundleName(baseName, locale);
        String resourceName = toResourceName(bundleName, format);

        File resourceFile = new File(localeDir, resourceName);
        if (resourceFile.exists() && resourceFile.isFile()) {
            long lastModified = resourceFile.lastModified();

            reload = lastModified > loadTime;
        } else {//from  w  ww.j av a2 s .  co  m
            reload = super.needsReload(baseName, locale, format, loader, bundle, loadTime);
        }
    } else {
        reload = super.needsReload(baseName, locale, format, loader, bundle, loadTime);
    }

    return reload;
}

From source file:org.teavm.libgdx.plugin.AssetsCopier.java

private void copyClasspathAssets(File dir) throws IOException {
    Enumeration<URL> resources = context.getClassLoader()
            .getResources("META-INF/teavm-libgdx/classpath-assets");
    Set<String> resourcesToCopy = new HashSet<>();
    while (resources.hasMoreElements()) {
        URL resource = resources.nextElement();
        InputStream input = resource.openStream();
        if (input == null) {
            continue;
        }//from w  w  w.  j av  a  2 s  .c  o m
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"))) {
            while (true) {
                String line = reader.readLine();
                if (line == null) {
                    break;
                }
                line = line.trim();
                if (line.isEmpty() || line.startsWith("#")) {
                    continue;
                }
                resourcesToCopy.add(line);
            }
        }
    }

    for (String resourceToCopy : resourcesToCopy) {
        File resource = new File(dir, resourceToCopy);
        if (resource.exists()) {
            URL url = context.getClassLoader().getResource(resourceToCopy);
            if (url != null && url.getProtocol().equals("file")) {
                try {
                    File sourceFile = new File(url.toURI());
                    if (sourceFile.exists() && sourceFile.length() == resource.length()
                            && sourceFile.lastModified() == resource.lastModified()) {
                        continue;
                    }
                } catch (URISyntaxException e) {
                    // fall back to usual resource copying
                }
            }
        }
        InputStream input = context.getClassLoader().getResourceAsStream(resourceToCopy);
        if (input == null) {
            continue;
        }
        resource.getParentFile().mkdirs();
        IOUtils.copy(input, new FileOutputStream(resource));
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.common.util.FileUtil.java

public static void createCompressedFiles(final List<String> fileNamesToBeCompressed,
        final String compressedFileName) throws IOException {

    final File compressedFile = new File(compressedFileName);
    for (final String fileNameToBeCompressed : fileNamesToBeCompressed) {
        final File fileToBeCompressed = new File(fileNameToBeCompressed);

        if (!fileToBeCompressed.exists()) {
            throw new IOException("Cache File does not exist: " + fileToBeCompressed.getPath());
        }/*from  w w  w.ja  va2 s.  c  o  m*/
    }
    final FileOutputStream outputFileStream = new FileOutputStream(compressedFile);
    final TarOutputStream tarStream = new TarOutputStream(new GZIPOutputStream(outputFileStream));
    try {
        for (final String fileNameToBeCompressed : fileNamesToBeCompressed) {
            final File fileToBeCompressed = new File(fileNameToBeCompressed);
            final String name = fileToBeCompressed.getName();
            final TarEntry tarAdd = new TarEntry(fileToBeCompressed);

            tarStream.setLongFileMode(TarOutputStream.LONGFILE_GNU);
            tarAdd.setModTime(fileToBeCompressed.lastModified());
            tarAdd.setName(name);
            tarStream.putNextEntry(tarAdd);

            FileInputStream inputStream = null;
            byte[] buffer = new byte[1024 * 64];
            try {

                inputStream = new FileInputStream(fileToBeCompressed);
                int nRead = inputStream.read(buffer, 0, buffer.length);
                while (nRead >= 0) {
                    tarStream.write(buffer, 0, nRead);
                    nRead = inputStream.read(buffer, 0, buffer.length);
                }

                tarStream.closeEntry();
            } finally {
                buffer = null;
                try {
                    if (inputStream != null) {
                        inputStream.close();
                    }
                } catch (IOException ie) {
                    logger.error("Error closing I/O streams " + ie.toString());
                }
            }

        }
    } finally {
        if (tarStream != null) {
            tarStream.close();
        }

    }
}

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

/**
 * <p>update</p>//from w ww  .  j av a  2s  .  c  om
 *
 * @throws java.io.IOException if any.
 * @throws org.exolab.castor.xml.MarshalException if any.
 * @throws org.exolab.castor.xml.ValidationException if any.
 */
public void update() throws IOException, MarshalException, ValidationException {
    getWriteLock().lock();
    try {
        final File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.POLLER_CONFIG_FILE_NAME);
        if (cfgFile.lastModified() > m_currentVersion) {
            m_currentVersion = cfgFile.lastModified();
            LogUtils.debugf(this, "init: config file path: %s", cfgFile.getPath());
            InputStream stream = null;
            try {
                stream = new FileInputStream(cfgFile);
                m_config = CastorUtils.unmarshal(PollerConfiguration.class, stream);
            } finally {
                IOUtils.closeQuietly(stream);
            }
            init();
            LogUtils.debugf(this, "init: finished loading config file: %s", cfgFile.getPath());
        }
    } finally {
        getWriteLock().unlock();
    }
}

From source file:net.rptools.lib.image.ThumbnailManager.java

private BufferedImage getCachedThumbnail(File file) {
    File thumbnailFile = getThumbnailFile(file);

    if (!thumbnailFile.exists()) {
        return null;
    }/*from   ww  w  .j a va 2s  . 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:azkaban.reportal.util.StreamProviderLocal.java

public String[] getOldFiles(String pathString, final long thresholdTime) throws Exception {
    File file = new File(pathString);

    if (!file.exists() || !file.isDirectory()) {
        return new String[0];
    }/*www.  j  a v a  2s  .  com*/

    File[] fileList = file.listFiles(new FileFilter() {
        public boolean accept(File file) {
            return file.lastModified() < thresholdTime;
        }
    });

    String[] files = new String[fileList.length];
    for (int i = 0; i < fileList.length; i++) {
        files[i] = fileList[i].getName();
    }

    return files;
}

From source file:de.undercouch.gradle.tasks.download.FunctionalDownloadTest.java

/**
 * Download a file once, then download again with 'onlyIfNewer'.
 * File changed between downloads./* w  w  w  .  j a va 2s  . c  o  m*/
 * @throws Exception if anything went wrong
 */
@Test
public void downloadOnlyIfNewerRedownloadsIfFileHasBeenUpdated() throws Exception {
    assertTaskSuccess(download(new Parameters(singleSrc, dest, false, false)));
    File src = new File(folder.getRoot(), TEST_FILE_NAME);
    assertTrue(src.setLastModified(src.lastModified() + 5000));
    assertTaskSuccess(download(new Parameters(singleSrc, dest, true, true)));
}

From source file:debop4k.core.io.FilexTest.java

@Test
@SneakyThrows//  w w w . j  ava2 s. c om
public void discoverLatestFiles() {
    //  3? ?  ?? ? .
    long since = DateTime.now().minusDays(5).getMillis();
    String start = ".";

    boolean filtered = false;

    //    Iterator<File> iter = FileUtils.iterateFiles(new File(start), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    Iterator<File> iter = FileUtils.iterateFiles(new File(start), new String[] { "class" }, true);
    while (iter.hasNext()) {
        File file = iter.next();
        log.trace("file={}", file.getName());
        if (!file.isDirectory()) {
            long filetime = file.lastModified();
            log.trace("filetime={}, since={}", filetime, since);
            if (filetime > since) {
                filtered = file.getCanonicalPath().contains("FilexTest");
                if (filtered)
                    break;
            }
        }
    }

    assertThat(filtered).isTrue();
}

From source file:org.montanafoodhub.base.get.AdHub.java

protected List<Ad> readFromFile(Context context) {
    List<Ad> myAdArr = new ArrayList<Ad>();
    try {//w  w  w.  j  a v a2  s. c  o m
        // getItem the time the file was last changed here
        File myFile = new File(context.getFilesDir() + "/" + fileName);
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
        String lastRefreshTSStr = sdf.format(myFile.lastModified());
        Log.w(HubInit.logTag, "Using file (" + fileName + ") last modified on : " + lastRefreshTSStr);
        lastRefreshTS = sdf.getCalendar();

        // create products from the file here
        InputStream inputStream = context.openFileInput(fileName);
        if (inputStream != null) {
            parseCSV(myAdArr, inputStream);
        }
        inputStream.close();
    } catch (FileNotFoundException e) {
        Log.e(HubInit.logTag, "File  (" + fileName + ") not found: " + e.toString());
    } catch (IOException e) {
        Log.e(HubInit.logTag, "Can not read file  (" + fileName + ") : " + e.toString());
    }
    Log.w(HubInit.logTag, "Number of Ad loaded: " + myAdArr.size());
    return myAdArr;
}