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.adobe.acs.commons.wcm.impl.FileImporter.java

@Override
@SuppressWarnings("squid:S3776")
public void importData(String schemeValue, String dataSource, Resource target) {
    if (scheme.equals(schemeValue)) {
        final File file = new File(dataSource);
        if (file.exists()) {
            Calendar fileLastMod = Calendar.getInstance();
            fileLastMod.setTimeInMillis(file.lastModified());
            String fileName = file.getName();
            String mimeType = mimeTypeService.getMimeType(fileName);

            final Node targetParent;
            final String targetName;

            Node node = target.adaptTo(Node.class);
            if (node != null) {
                try (FileInputStream stream = new FileInputStream(file)) {
                    if (node.isNodeType(JcrConstants.NT_FILE)) {
                        // assume that we are intending to replace this file
                        targetParent = node.getParent();
                        targetName = node.getName();
                        Calendar nodeLastMod = JcrUtils.getLastModified(node);
                        if (!nodeLastMod.before(fileLastMod)) {
                            log.info("File '{}' does not have a newer timestamp than '{}'. Skipping import.",
                                    dataSource, target);
                            return;
                        }//from  w  w w . ja  v a 2s.c  o  m
                    } else {
                        // assume that we are creating a new file under the current node
                        targetParent = node;
                        targetName = fileName;
                        if (targetParent.hasNode(targetName)) {
                            Node targetNode = targetParent.getNode(targetName);
                            Calendar nodeLastMod = JcrUtils.getLastModified(targetNode);
                            if (!nodeLastMod.before(fileLastMod)) {
                                log.info(
                                        "File '{}' does not have a newer timestamp than '{}'. Skipping import.",
                                        dataSource, targetNode.getPath());
                                return;
                            }
                        }
                    }

                    JcrUtils.putFile(targetParent, targetName, mimeType, stream);
                    node.getSession().save();
                } catch (RepositoryException e) {
                    throw new ImportException(
                            "Unable to import from file '" + dataSource + "' to '" + target.getPath() + "'", e);
                } catch (IOException e) {
                    throw new ImportException("Unexpected IOException while importing", e);
                }
            } else {
                log.warn("Target '{}' is not a JCR node. Skipping import from '{}'.", target.getPath(),
                        dataSource);
            }
        } else {
            log.warn("File at '{}' does not exist. Skipping import.", dataSource);
        }
    } else {
        log.warn("Unrecognized scheme '{}' passed to importData()", schemeValue);
    }
}

From source file:com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScannerZipInstaller.java

private void downloadIfModified(File scannerExpansionDirectory, File versionFile, String downloadUrl)
        throws IOException, IntegrationException, ArchiveException {
    long lastTimeDownloaded = versionFile.lastModified();
    logger.debug(String.format("last time downloaded: %d", lastTimeDownloaded));

    Request downloadRequest = new Request.Builder(downloadUrl).build();
    Optional<Response> optionalResponse = intHttpClient.executeGetRequestIfModifiedSince(downloadRequest,
            lastTimeDownloaded);/*  www .  j  a  v  a  2s. c  o m*/
    if (optionalResponse.isPresent()) {
        Response response = optionalResponse.get();
        try {
            logger.info("Downloading the Black Duck Signature Scanner.");
            try (InputStream responseStream = response.getContent()) {
                logger.info(String.format(
                        "If your Black Duck server has changed, the contents of %s may change which could involve deleting files - please do not place items in the expansion directory as this directory is assumed to be under blackduck-common control.",
                        scannerExpansionDirectory.getAbsolutePath()));
                cleanupZipExpander.expand(responseStream, scannerExpansionDirectory);
            }
            long lastModifiedOnServer = response.getLastModified();
            versionFile.setLastModified(lastModifiedOnServer);

            ScanPaths scanPaths = scanPathsUtility
                    .determineSignatureScannerPaths(scannerExpansionDirectory.getParentFile());
            File javaExecutable = new File(scanPaths.getPathToJavaExecutable());
            File oneJar = new File(scanPaths.getPathToOneJar());
            File scanExecutable = new File(scanPaths.getPathToScanExecutable());
            javaExecutable.setExecutable(true);
            oneJar.setExecutable(true);
            scanExecutable.setExecutable(true);

            logger.info(String.format("Black Duck Signature Scanner downloaded successfully."));
        } finally {
            response.close();
        }
    } else {
        logger.debug(
                "The Black Duck Signature Scanner has not been modified since it was last downloaded - skipping download.");
    }
}

From source file:de.rallye.api.Groups.java

@GET
@Path("{groupID}/avatar")
@Produces("image/jpeg")
public File getGroupAvatar(@PathParam("groupID") int groupID, @Context Request request) {
    File avatar = new File(config.getDataDirectory() + "game/" + groupID + "/avatar.jpg");

    HttpCacheHandling.checkModifiedSince(request, avatar.lastModified());

    return avatar;
}

From source file:de.viaboxx.nlstools.formats.BundleWriterFlexClass.java

/**
 * true when generation is neccessary, false when up-to-date
 *
 * @throws java.io.FileNotFoundException
 *//*from  w w  w  .j  a  v  a 2 s .co m*/
@Override
protected boolean needsNewFiles() throws FileNotFoundException {
    if (currentBundle.getInterfaceName() == null)
        return false;
    File outfile = new File(getInterfaceFileName());
    if (!outfile.exists()) {
        return true;
    }
    File infile = new File(configFile);
    if (!infile.exists()) {
        throw new FileNotFoundException(infile + " not found");
    }
    return (infile.lastModified() > outfile.lastModified());
}

From source file:com.comcast.cdn.traffic_control.traffic_router.neustar.data.NeustarDatabaseUpdater.java

public Date getDatabaseBuildDate() {
    File[] neustarDatabaseFiles = neustarDatabaseDirectory.listFiles();

    if (neustarDatabaseFiles == null || neustarDatabaseFiles.length == 0) {
        return null;
    }/*from w  w  w. j a  v a  2s .com*/

    long modifiedTimestamp = 0;

    for (File file : neustarDatabaseFiles) {
        if (file.isDirectory()) {
            continue;
        }

        if (modifiedTimestamp == 0 || file.lastModified() < modifiedTimestamp) {
            modifiedTimestamp = file.lastModified();
        }
    }

    return modifiedTimestamp > 0 ? new Date(modifiedTimestamp) : null;
}

From source file:com.googlecode.fascinator.portal.services.impl.PortalManagerImpl.java

private Portal loadPortal(String name) {
    Portal portal = null;/*from w w w.  j av  a  2 s. c o m*/
    File portalFile = new File(new File(portalsDir, name), PORTAL_JSON);
    if (portalFile.exists()) {
        lastModified.put(name, portalFile.lastModified());
        portalFiles.put(name, portalFile);
        try {
            portal = new Portal(portalFile);
            add(portal);
            // log.info("Loaded portal: " + portal);
        } catch (IOException e) {
            log.warn("Portal: " + name + " failed to load", e);
        }
    }
    return portal;
}

From source file:net.pms.dlna.RealFile.java

public RealFile(File file) {
    getConf().getFiles().add(file);
    setLastModified(file.lastModified());
}

From source file:com.moneydance.modules.features.importlist.controller.FileTableModel.java

@Override
public Object getValueAt(final int row, final int column) {
    if (row >= this.files.size()) {
        this.fireTableDataChanged();
        throw new IllegalArgumentException(
                String.format("Could not find value for row %d, column %d", row, column));
    }/*from  w w w  .ja v  a2 s .  co  m*/
    String columnName = this.getColumnName(column);

    if (this.settings.getDescName().equals(columnName)) {
        final File file = this.files.get(row);
        return file.getName();
    }
    if (this.settings.getDescModified().equals(columnName)) {
        final File file = this.files.get(row);
        return new Date(file.lastModified());
    }
    if (this.settings.getDescImport().equals(columnName)) {
        return this.localizable.getLabelImportOneButton();
    }
    if (this.settings.getDescDelete().equals(columnName)) {
        return this.localizable.getLabelDeleteOneButton();
    }
    throw new IllegalArgumentException(
            String.format("Could not find value for row %d, column %d", row, column));
}

From source file:com.ning.arecibo.util.timeline.persistent.Replayer.java

public int readAll(final boolean deleteFiles, final @Nullable DateTime minStartTime,
        final Function<HostSamplesForTimestamp, Void> fn) {
    final Collection<File> files = FileUtils.listFiles(new File(path), new String[] { "bin" }, false);
    int filesSkipped = 0;
    for (final File file : FILE_ORDERING.sortedCopy(files)) {
        try {/*from   w ww .j a v  a  2s.c om*/
            // 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:edu.unc.lib.dl.services.BatchIngestQueue.java

/**
 * @return//from   w ww.j a v a2 s  .c  o m
 */
public File[] getReadyIngestDirectories() {
    File[] batchDirs = this.queuedDirectory.listFiles(new FileFilter() {
        @Override
        public boolean accept(File arg0) {
            if (arg0.isDirectory()) {
                String[] readyFiles = arg0.list(new FilenameFilter() {
                    @Override
                    public boolean accept(File dir, String name) {
                        return (READY_FILE.equals(name));
                    }
                });
                if (readyFiles != null && readyFiles.length > 0) {
                    return true;
                }
            }
            return false;
        }
    });
    if (batchDirs != null) {
        Arrays.sort(batchDirs, new Comparator<File>() {
            @Override
            public int compare(File o1, File o2) {
                if (o1 == null || o2 == null)
                    return 0;
                return (int) (o1.lastModified() - o2.lastModified());
            }
        });
        return batchDirs;
    } else {
        return new File[] {};
    }
}