List of usage examples for java.io File lastModified
public long lastModified()
From source file:com.fiveamsolutions.nci.commons.mojo.copywebfiles.CopyWebFilesMojo.java
/** * @return// w w w . java 2 s. c o m * @throws MojoExecutionException */ private Collection<File> getLatestDeploymentDirectories() throws MojoExecutionException { Set<File> matchSet = new HashSet<File>(); File latestDeployDirectory = deployDirectory; if (StringUtils.isNotEmpty(deployDirectoryPattern)) { IOFileFilter fileFilter = new WildcardFileFilter(deployDirectoryPattern); fileFilter = FileFilterUtils.andFileFilter(DirectoryFileFilter.DIRECTORY, fileFilter); File[] matches = deployDirectory.listFiles((FileFilter) fileFilter); if (ArrayUtils.isEmpty(matches)) { throw new MojoExecutionException("No directories found that match the given pattern"); } latestDeployDirectory = matches[0]; for (File match : matches) { if (match.lastModified() > latestDeployDirectory.lastModified()) { latestDeployDirectory = match; } if (copyToAllMatches) { matchSet.add(match); } } } matchSet.add(latestDeployDirectory); return appendSubDirectory(matchSet); }
From source file:com.tc.websocket.queue.TempFileMonitor.java
public void run() { if (TaskRunner.getInstance().isClosing()) { return;//from w w w .j a va2s . c om } try { File temp = File.createTempFile("temp", "temp"); String absolutePath = temp.getAbsolutePath(); String tempFilePath = absolutePath.substring(0, absolutePath.lastIndexOf(File.separator)); System.out.println("cleaning out directory " + tempFilePath); File tempdir = new File(tempFilePath); File[] files = tempdir.listFiles(); temp.delete();//cleanup for (File file : files) { String name = file.getName(); if (file.exists() && name.startsWith("eo") && name.endsWith("tm")) { //calculate the age Date lastmod = new Date(file.lastModified()); long minutes = DateUtils.getTimeDiffMin(lastmod, new Date()); if (minutes >= 5) { FileUtils.deleteQuietly(file); } } } } catch (Exception e) { logger.log(Level.SEVERE, null, e); } }
From source file:it.grid.storm.namespace.config.xml.XMLReloadingStrategy.java
/** * Check if the configuration has changed since the last time it was loaded. * //w w w. j av a 2s.c o m * @return a flag whether the configuration has changed */ @Override protected boolean hasChanged() { // log.debug("Checking if Namespace Configuration is changed.."); File file = getConfigurationFile(); // File file = thigetFile(); if (file == null || !file.exists()) { return false; } boolean result = file.lastModified() > lastModified; if (result) { notifyNeeded(); log.debug(" <<<<< Namespace Configuration is CHANGED ---> Notify needed.."); } return result; }
From source file:com.blackducksoftware.tools.scmconnector.integrations.ftp.FTPConnector.java
@Override public int sync() { try {// w w w. j a va2s .c o m FTPClient client = new FTPClient(); client.connect(server); client.login(user, password); client.changeDirectory(path); FTPFile[] list = client.list(); String parentPath = getFinalSourceDirectory(); File dir = new File(parentPath); if (!dir.exists()) { dir.mkdir(); } deleteFileInTargetDirectoryNotExistingInSource(dir, list); for (FTPFile f : list) { if (f.getType() == FTPFile.TYPE_FILE) { File targetFile = new File(parentPath, f.getName()); if (f.getModifiedDate().getTime() != targetFile.lastModified()) { log.info("Obtaining file: " + f.getName()); client.download(f.getName(), targetFile); targetFile.setLastModified(f.getModifiedDate().getTime()); } } else if (f.getType() == FTPFile.TYPE_DIRECTORY) { log.info("Inspecting directory: " + f.getName()); downloadFiles(parentPath, client, f); } } } catch (Exception e) { log.error("Error performing FTP operation", e); return 1; } return 0; }
From source file:com.fujitsu.dc.core.eventlog.ArchiveLogCollection.java
/** * ????./*www. j a v a2 s .c o m*/ */ public void createFileInformation() { File archiveDir = new File(this.directoryPath); // ??????????????????? if (!archiveDir.exists()) { return; } File[] fileList = archiveDir.listFiles(); for (File file : fileList) { // ?? long fileUpdated = file.lastModified(); // ?????? if (this.updated < fileUpdated) { this.updated = fileUpdated; } BasicFileAttributes attr = null; ZipFile zipFile = null; long fileCreated = 0L; long size = 0L; try { // ??? attr = Files.readAttributes(file.toPath(), BasicFileAttributes.class); fileCreated = attr.creationTime().toMillis(); // ????API??????????????????? zipFile = new ZipFile(file); Enumeration<? extends ZipEntry> emu = zipFile.entries(); while (emu.hasMoreElements()) { ZipEntry entry = (ZipEntry) emu.nextElement(); if (null == entry) { log.info("Zip file entry is null."); throw DcCoreException.Event.ARCHIVE_FILE_CANNOT_OPEN; } size += entry.getSize(); } } catch (ZipException e) { log.info("ZipException", e); throw DcCoreException.Event.ARCHIVE_FILE_CANNOT_OPEN; } catch (IOException e) { log.info("IOException", e); throw DcCoreException.Event.ARCHIVE_FILE_CANNOT_OPEN; } finally { IOUtils.closeQuietly(zipFile); } // ??????API???????????????(.zip)?????? String fileName = file.getName(); String fileNameWithoutZip = fileName.substring(0, fileName.length() - ".zip".length()); String fileUrl = this.url + "/" + fileNameWithoutZip; ArchiveLogFile archiveFile = new ArchiveLogFile(fileCreated, fileUpdated, size, fileUrl); this.archivefileList.add(archiveFile); log.info(String.format("filename:%s created:%d updated:%d size:%d", file.getName(), fileCreated, fileUpdated, size)); } }
From source file:de.hybris.platform.acceleratorservices.dataimport.batch.FileOrderComparator.java
@Override public int compare(final File file, final File otherFile) { // invert priority setting so files with higher priority go first int result = getPriority(otherFile).compareTo(getPriority(file)); if (result == 0) { result = Long.valueOf(file.lastModified()).compareTo(Long.valueOf(otherFile.lastModified())); }/*from w ww . j a v a 2 s .c o m*/ return result; }
From source file:io.personium.core.eventlog.ArchiveLogCollection.java
/** * ????./* w w w. j av a 2s.c o m*/ */ public void createFileInformation() { File archiveDir = new File(this.directoryPath); // ??????????????????? if (!archiveDir.exists()) { return; } File[] fileList = archiveDir.listFiles(); for (File file : fileList) { // ?? long fileUpdated = file.lastModified(); // ?????? if (this.updated < fileUpdated) { this.updated = fileUpdated; } BasicFileAttributes attr = null; ZipFile zipFile = null; long fileCreated = 0L; long size = 0L; try { // ??? attr = Files.readAttributes(file.toPath(), BasicFileAttributes.class); fileCreated = attr.creationTime().toMillis(); // ????API??????????????????? zipFile = new ZipFile(file); Enumeration<? extends ZipEntry> emu = zipFile.entries(); while (emu.hasMoreElements()) { ZipEntry entry = (ZipEntry) emu.nextElement(); if (null == entry) { log.info("Zip file entry is null."); throw PersoniumCoreException.Event.ARCHIVE_FILE_CANNOT_OPEN; } size += entry.getSize(); } } catch (ZipException e) { log.info("ZipException", e); throw PersoniumCoreException.Event.ARCHIVE_FILE_CANNOT_OPEN; } catch (IOException e) { log.info("IOException", e); throw PersoniumCoreException.Event.ARCHIVE_FILE_CANNOT_OPEN; } finally { IOUtils.closeQuietly(zipFile); } // ??????API???????????????(.zip)?????? String fileName = file.getName(); String fileNameWithoutZip = fileName.substring(0, fileName.length() - ".zip".length()); String fileUrl = this.url + "/" + fileNameWithoutZip; ArchiveLogFile archiveFile = new ArchiveLogFile(fileCreated, fileUpdated, size, fileUrl); this.archivefileList.add(archiveFile); log.info(String.format("filename:%s created:%d updated:%d size:%d", file.getName(), fileCreated, fileUpdated, size)); } }
From source file:com.xtructure.xevolution.evolution.impl.AbstractEvolutionExperiment.java
protected Population<D> createPopulation(int idNumber) throws IOException, XMLStreamException { if (getOutputDir() == null) { return getGeneticsFactory().createPopulation(idNumber); }/*w w w. j a v a2 s.c om*/ File populationFile = null; long mod = Long.MIN_VALUE; for (File file : getOutputDir().listFiles()) { if (file.lastModified() > mod && file.getName().endsWith(".xml")) { mod = file.lastModified(); populationFile = file; } } if (populationFile == null) { return getGeneticsFactory().createPopulation(idNumber); } return XmlReader.read(populationFile); }
From source file:javafxapplication2.FXMLDocumentController.java
private void display(String path) { File home = new File(path); File[] subFiles = home.listFiles(); for (File subFile : subFiles) { TableRowDataBean rowData = new TableRowDataBean(subFile.getName(), subFile.length(), subFile.getPath(), DateFormatUtils.format(new Date(subFile.lastModified()), DATE_PATTERN)); rowDataList.add(rowData);//from w w w .j av a2s. com } table1.getItems().clear(); table1.setItems(rowDataList); table1.layout(); }