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:org.shept.util.FtpFileCopy.java

/**
 * Compare the source path and the destination path for filenames with the filePattern
 * e.g. *.bak, *tmp and copy these files to the destination dir if they are not present at the
 * destination or if they have changed (by modifactionDate).
 * Copying is done from local directory into remote ftp destination directory.
 * /* w ww  .  jav  a 2 s .  com*/
 * @param destPath
 * @param localSourcePath
 * @param filePattern
 * @return the number of files being copied
 * @throws IOException 
 */
public Integer syncPush(String localSourcePath, FTPClient ftpDest, String filePattern) throws IOException {
    // check for new files since the last check which need to be copied

    Integer number = 0;
    SortedMap<FileNameDate, FTPFile> destMap = fileMapByNameAndDate(ftpDest, filePattern);
    SortedMap<FileNameDate, File> sourceMap = FileUtils.fileMapByNameAndDate(localSourcePath, filePattern);
    // identify the list of source files different from their destinations
    for (FileNameDate fk : destMap.keySet()) {
        sourceMap.remove(fk);
    }

    // copy the list of files from source to destination
    for (File file : sourceMap.values()) {
        logger.debug(file.getName() + ": " + new Date(file.lastModified()));

        try {
            // only copy file that don't exist yet
            if (ftpDest.listNames(file.getName()).length == 0) {
                FileInputStream fin = new FileInputStream(file);
                String tmpName = "tempFile";
                boolean rc = ftpDest.storeFile(tmpName, fin);
                fin.close();
                if (rc) {
                    rc = ftpDest.rename(tmpName, file.getName());
                    number++;
                }
                if (!rc) {
                    ftpDest.deleteFile(tmpName);
                }
            }
        } catch (Exception ex) {
            logger.error("Ftp FileCopy did not succeed (using " + file.getName() + ")" + " FTP reported error  "
                    + ftpDest.getReplyString());
        }
    }
    return number;
}

From source file:cprasmu.rascam.camera.FileSystemModel.java

public int getFileCount() {

    int count = -1;
    File f = new File(initialPath);
    //imageFileMap.clear();
    //totalFileCount = 0;
    //fileDataSize = 0;

    if (f.isDirectory()) {

        File[] files = f.listFiles();

        Arrays.sort(files, new Comparator<File>() {
            public int compare(File f1, File f2) {
                return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
            }/* w w w . ja v a 2 s .c o m*/
        });

        for (File file : files) {
            if (file.getName().endsWith(".jpg") || file.getName().endsWith(".h264")) {
                if (file.getName().startsWith("drone_")) {

                    /*
                    if(!imageFileMap.containsKey(file.getName())){
                       imageFileMap.put(file.getName(), file);
                       fileList.add(file);
                    }
                    */

                    String name = file.getName();
                    name = name.replace("drone_", "");

                    if (name.contains("_")) {
                        name = name.split("_")[0];
                    } else {
                        if (name.contains(".")) {
                            name = name.split("[.]")[0];
                        }
                    }
                    if (Integer.parseInt(name) > count) {
                        count = Integer.parseInt(name);
                    }
                }
            }
        }
    }

    return count + 1;

}

From source file:com.qwerky.tools.foldersync.Analyser.java

private boolean requireSync(File in, File out) {
    if (out.exists()) {
        try {/*from  w ww  . j  a  va  2 s . c  o  m*/
            byte[] inmd5 = DigestUtils.md5(new FileInputStream(in));
            byte[] outmd5 = DigestUtils.md5(new FileInputStream(out));

            return (in.length() != out.length()) || (in.lastModified() > out.lastModified())
                    || !(Arrays.equals(inmd5, outmd5));
        } catch (IOException ioe) {
            return true;
        }
    }
    return true;
}

From source file:cn.dreampie.coffeescript.compiler.CoffeeCompiler.java

/**
 * Compiles the COFFEE input <code>File</code> to CSS and writes it to the specified output <code>File</code>.
 *
 * @param input  The COFFEE input <code>File</code> to compile.
 * @param output The output <code>File</code> to write the CSS to.
 * @param force  'false' to only compile the COFFEE input file in case the COFFEE source has been modified (including imports) or the output file does not exists.
 * @throws java.io.IOException If the COFFEE file cannot be read or the output file cannot be written.
 *///from  w w  w .  j  a v a2 s  .  co  m
public void compile(File input, File output, boolean force) throws IOException, CoffeeException {
    if (force || !output.exists() || output.lastModified() < input.lastModified()) {
        String data = compile(input);
        FileUtils.writeStringToFile(output, data, encoding);
    }
}

From source file:org.killbill.billing.plugin.meter.timeline.persistent.Replayer.java

public int readAll(final boolean deleteFiles, @Nullable final DateTime minStartTime,
        final Function<SourceSamplesForTimestamp, Void> fn) {
    final List<File> files = findCandidates();
    int filesSkipped = 0;
    for (final File file : FILE_ORDERING.sortedCopy(files)) {
        try {/*from  w  ww . ja v a  2 s  .  c  o  m*/
            // Skip files whose last modification date is is earlier than the first start time.
            if (minStartTime != null && file.lastModified() < minStartTime.getMillis()) {
                filesSkipped++;
                continue;
            }
            read(file, fn);
            if (shuttingDown.get()) {
                break;
            }

            if (deleteFiles) {
                if (!file.delete()) {
                    log.warn("Unable to delete file: {}", file.getAbsolutePath());
                }
            }
        } catch (IOException e) {
            log.warn("Exception replaying file: {}", file.getAbsolutePath(), e);
        }
    }
    return filesSkipped;
}

From source file:maven.plugin.javafmt.JavaFormatterMojo.java

protected boolean shouldFormat(File javaFile) {
    String propertyKey = javaFile.getAbsolutePath();
    String propertyValue = status.getProperty(propertyKey, "0");
    ////from  www  .  j  av a 2 s. c  o  m
    if (javaFile.lastModified() > Long.parseLong(propertyValue)) {
        //
        return true;
    }
    //
    return false;
}

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

private void transformFile(final File file) throws MojoFailureException {
    final File destination = new DestinationFileCreator(sourceDirectory, outputDirectory, outputFileFormat)
            .create(file);/*from w ww . ja v a  2  s.c  o m*/
    if (!force && destination.exists() && file.lastModified() < destination.lastModified()) {
        if (verbose) {
            getLog().info("Skips transforming metadata, because source is older than output file: "
                    + destination.getAbsolutePath());
        }
        return;
    }

    getLog().info("Transforming metadata of the file: " + file.getAbsolutePath());
    final FileMetadata metadata = createMetadata(file);
    final String document = transformMetadata(metadata);
    saveDocument(document, destination);
}

From source file:com.qwazr.compiler.JavaCompiler.java

private Collection<File> filterUptodate(File parentDir, File[] javaSourceFiles) {
    if (javaSourceFiles == null)
        return null;
    final Collection<File> finalJavaFiles = new ArrayList<File>();
    if (javaSourceFiles.length == 0)
        return finalJavaFiles;
    final File parentClassDir = new File(javaClassesDirectory,
            parentDir.getAbsolutePath().substring(javaSourcePrefixSize));
    for (File javaSourceFile : javaSourceFiles) {
        final File classFile = new File(parentClassDir,
                FilenameUtils.removeExtension(javaSourceFile.getName()) + ".class");
        if (classFile.exists() && classFile.lastModified() > javaSourceFile.lastModified())
            continue;
        finalJavaFiles.add(javaSourceFile);
    }/*w w w.ja v a  2s . co m*/
    return finalJavaFiles;
}

From source file:io.smartspaces.util.io.directorywatcher.SimpleDirectoryWatcher.java

/**
 * Find all files added or modified since the last scan.
 * //from  w w  w . j  a  va2s. c o m
 * <p>
 * This modifies the seen map.
 *
 * @param currentScan
 *          the files from the current scan
 */
private void findAddedFiles(Set<File> currentScan) {
    for (File fileFromCurrent : currentScan) {
        Long modifiedTime = fileFromCurrent.lastModified();
        Long lastModifiedTime = filesSeen.put(fileFromCurrent, modifiedTime);
        if (lastModifiedTime == null) {
            signalFileAdded(fileFromCurrent);
        } else if (!lastModifiedTime.equals(modifiedTime)) {
            signalFileModified(fileFromCurrent);
        }
    }
}

From source file:jp.co.opentone.bsol.linkbinder.view.logo.ProjectLogoManager.java

/**
 * ???????./*from w ww .j ava  2 s.co m*/
 *
 * @param projectId ID
 * @param ifModifiedSince If-Modified-Since
 * @return true:?? false:?????
 */
public boolean isModified(String projectId, String ifModifiedSince) {
    if (log.isDebugEnabled()) {
        log.debug("projectId[" + projectId + "]");
        log.debug("ifModifiedSince[" + ifModifiedSince + "]");
    }

    if (StringUtils.isEmpty(ifModifiedSince)) {
        // If-Modified-Since()????true
        return true;
    }

    long ifModifiedSinceLongValue = 0;
    try {
        Date ifModifiedSinceDateValue = DateUtil.parseDate(ifModifiedSince);
        ifModifiedSinceLongValue = ifModifiedSinceDateValue.getTime();
        if (log.isDebugEnabled()) {
            log.debug("ifModifiedSinceDateValue[" + ifModifiedSinceDateValue + "]");
            log.debug("ifModifiedSinceLongValue[" + ifModifiedSinceLongValue + "]");
        }
    } catch (DateParseException e) {
        // ?????????
        log.warn("If-Modified-Since parse error[" + ifModifiedSince + "]", e);
        return true;
    }

    String logoFile = detectLogoFile(projectId);
    File f = new File(logoFile);
    if (log.isDebugEnabled()) {
        log.debug("f.exists[" + f.exists() + "]");
        log.debug("f.lastModified[" + f.lastModified() + "]");
    }

    // ???????1/1000?(12:34:56.789?12:34:56.000??????)
    //CHECKSTYLE:OFF
    if (!f.exists() || f.lastModified() / 1000 != ifModifiedSinceLongValue / 1000) {
        return true;
    }
    //CHECKSTYLE:ON

    if (log.isDebugEnabled()) {
        log.debug("return false");
    }
    return false;
}