List of usage examples for java.io File lastModified
public long lastModified()
From source file:org.zilverline.extractors.AbstractExtractor.java
/** * Set the file and all file related information of the document, such as length and modification date. * // w w w. j a va2 s . c o m * @param f The file that is being parsed */ public final void setFile(final File f) { fileInfo.setFile(f); fileInfo.setSize(f.length()); fileInfo.setModificationDate(f.lastModified()); }
From source file:com.xindian.mvc.result.velocity.WebappResourceLoader.java
/** * Checks to see when a resource was last modified * //from www. j a v a2s .c o m * @param resource * Resource the resource to check * @return long The time when the resource was last modified or 0 if the * file can't be read */ public long getLastModified(Resource resource) { String rootPath = servletContext.getRealPath("/"); if (rootPath == null) { // rootPath is null if the servlet container cannot translate the // virtual path to a real path for any reason (such as when the // content is being made available from a .war archive) return 0; } File cachedFile = getCachedFile(rootPath, resource.getName()); if (cachedFile.canRead()) { return cachedFile.lastModified(); } else { return 0; } }
From source file:hudson.util.io.ZipArchiver.java
@Override public void visitSymlink(final File f, final String target, final String relativePath) throws IOException { int mode = IOUtils.lmode(f); ZipArchiveEntry zae = new ZipArchiveEntry(relativePath); if (mode != -1) { zae.setUnixMode(mode);//from w w w. j a v a2 s .co m } zae.setTime(f.lastModified()); zip.putArchiveEntry(zae); zip.write(target.getBytes(StandardCharsets.UTF_8), 0, target.length()); zip.closeArchiveEntry(); entriesWritten++; }
From source file:au.com.addstar.objects.Plugin.java
public void setLatestFile() { File pluginDir = new File(SpigotUpdater.downloadDir, getName()); File latest = null;/* ww w . j ava 2s .c o m*/ if (pluginDir.exists()) { File[] files = pluginDir.listFiles(); if (files != null) { for (File file : files) { if (latest != null) { if (file.lastModified() > latest.lastModified()) { latest = file; } } else { latest = file; } } if (latest != null) setLatestFile(latest); } } }
From source file:de.uzk.hki.da.at.ATSipKeepModDates.java
public void doTest(boolean withCompression) throws Exception { File tarArchive = new File(sourceName + ".tgz"); ArchiveBuilder builder = ArchiveBuilderFactory.getArchiveBuilderForFile(tarArchive); builder.unarchiveFolder(tarArchive, sourceDir); File s1;/* w ww . j av a 2 s.c o m*/ if (withCompression) { s1 = new File("target/atTargetDir/" + sip + ".tgz"); } else { s1 = new File("target/atTargetDir/" + sip + ".tar"); } File unpackedSip = new File("target/atTargetDir/" + sip); String cmd = "./SipBuilder-Unix.sh -rights=\"" + ATWorkingDirectory.CONTRACT_RIGHT_LICENSED.getAbsolutePath() + "\" -source=\"" + sourceDir.getAbsolutePath() + "/\" -destination=\"" + targetDir.getAbsolutePath() + "/\" -workspace=\"" + workDir.getAbsolutePath() + "/\" -single"; if (!withCompression) { cmd += " -noCompression"; } p = Runtime.getRuntime().exec(cmd, null, new File("target/installation")); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); String s = ""; // read the output from the command System.out.println("Here is the standard output of the command:\n"); while ((s = stdInput.readLine()) != null) { System.out.println(s); } // read any errors from the attempted command System.out.println("Here is the standard error of the command (if any):\n"); while ((s = stdError.readLine()) != null) { System.out.println(s); } assertTrue(s1.exists()); assertFalse(new File(workDir + sip).exists()); // Tests content of the first SIP builder = ArchiveBuilderFactory.getArchiveBuilderForFile(s1); try { builder.unarchiveFolder(s1, targetDir); } catch (Exception e) { throw new RuntimeException("couldn't unpack archive", e); } long moddi; Date modDate; String tagStr; SimpleDateFormat dateForm = new SimpleDateFormat("dd.MM.yyyy"); dateForm.setTimeZone(TimeZone.getTimeZone("GMT")); File file = new File(unpackedSip, "data/unter1/unter2/M00000.jpg"); System.out.println("File:" + file.getAbsolutePath() + " exists:" + file.exists()); moddi = file.lastModified(); modDate = new Date(moddi); tagStr = dateForm.format(modDate); if (!tagStr.equals("21.10.2015")) { System.out.println("Unexpected Date: >" + tagStr + "< Expected: >21.10.2015<"); } assertTrue(tagStr.equals("21.10.2015")); moddi = new File(unpackedSip, "data/West_mets.xml").lastModified(); modDate = new Date(moddi); tagStr = dateForm.format(modDate); assertTrue(tagStr.equals("23.12.1978")); moddi = new File(unpackedSip, "data/unter1/Pest17.bmp").lastModified(); modDate = new Date(moddi); tagStr = dateForm.format(modDate); assertTrue(tagStr.equals("25.10.2012")); }
From source file:net.thackbarth.sparrow.FileMover.java
/** * This method move all MusicTrack stored in the database to the new target if the * filePathCorrect is false.// ww w . j a va2s . c o m * * @param session the session to the database */ public void moveFiles(Session session) { int count = 0; List list; do { Criteria criteria = session.createCriteria(MusicTrack.class) .add(Restrictions.eq("filePathCorrect", false)).setMaxResults(configuration.getBatchSize()); list = criteria.list(); if (!list.isEmpty()) { for (Object obj : list) { MusicTrack track = (MusicTrack) obj; File srcFile = new File(configuration.getDataFolder() + track.getFilePath()); File targetFile = new File(configuration.getDataFolder() + track.getTargetFilePath()); boolean errorFree = srcFile.exists(); File targetParent = targetFile.getParentFile(); if (!targetParent.exists()) { errorFree &= targetParent.mkdirs(); } if (errorFree) { logger.info("Move " + srcFile.getAbsolutePath() + " to " + targetFile.getAbsolutePath()); moveFile(srcFile, targetFile); } // update the database File updatedTargetFile = new File(configuration.getDataFolder() + track.getTargetFilePath()); track.setFilePathCorrect(true); track.setFilePath(track.getTargetFilePath()); track.setModificationDate(updatedTargetFile.lastModified()); session.update(track); } count += list.size(); progress.info("Moved files: " + count); session.flush(); } } while (!list.isEmpty()); }
From source file:io.smartspaces.util.io.directorywatcher.SimpleDirectoryWatcher.java
@Override public Set<File> startupWithScan(SmartSpacesEnvironment environment, long period, TimeUnit unit) { Set<File> currentScan = scanAllDirectories(); for (File file : currentScan) { filesSeen.put(file, file.lastModified()); }//from w w w. j a va 2 s.c o m startup(environment, period, unit); return currentScan; }
From source file:com.cubeia.ProtocolGeneratorMojo.java
private boolean isProtocolFileNewerThanGeneratedCode(File protocolFile, File outputDir) { return protocolFile.lastModified() > outputDir.lastModified(); }
From source file:io.github.eternalbits.compactvd.CompactVD.java
private void compact(File file, int options) throws IOException { long mtime = file.lastModified(); task = DiskImageProgress.COMPACT;/*from w w w.java2 s. c o m*/ try (RandomAccessFile check = new RandomAccessFile(file, "r")) { // is file? try (DiskImage image = DiskImages.open(file, "rw")) { FileLock fileLock = image.tryLock(); verboseProgress(SEARCHING_SPACE); image.addObserver(this, false); image.optimize(options); image.removeObserver(this); if (!isCancelled()) { verboseProgress("Compacting " + file.getName()); image.addObserver(this, false); image.compact(); image.removeObserver(this); } fileLock.release(); } } finally { System.out.println(String.format(mtime != file.lastModified() ? IMAGE_CHANGED : IMAGE_NOT_CHANGED, file.getName())); } }
From source file:org.openbaton.vnfm.generic.utils.LogDispatcher.java
private void deleteFilesRecursively(File top, long now) { for (File f : top.listFiles()) { if (f.isDirectory()) { if (f.listFiles().length > 0) { deleteFilesRecursively(f, now); } else { f.delete();//from w w w .j a v a 2s. com } } else if (now - f.lastModified() > this.old * 60000) { this.log.debug("Removed " + f.getName()); f.delete(); } } }