List of usage examples for java.io File lastModified
public long lastModified()
From source file:jobhunter.persistence.Persistence.java
private void updateLastMod(final File file, final MessageDigest md) throws IOException { this.lastModification = file.lastModified(); this.md5sum = md.digest(); l.debug("File was last modified on {} with MD5 {}", lastModification, this.md5sum.toString()); }
From source file:cc.creativecomputing.io.CCIOUtil.java
public static boolean isNewer(final File theA, final File theB) { if (theA.exists() && !theB.exists()) return true; return theA.lastModified() > theB.lastModified(); }
From source file:com.ibm.jaggr.core.util.ZipUtilTest.java
public void assertFilesSame(File file1, File file2) throws IOException { Assert.assertEquals(file1.length(), file2.length()); Assert.assertTrue(Math.abs(file1.lastModified() - file2.lastModified()) < 2000); Assert.assertEquals(Files.toString(file1, Charsets.UTF_8), Files.toString(file2, Charsets.UTF_8)); }
From source file:com.izforge.izpack.installer.unpacker.Pack200FileUnpackerTest.java
/** * Verifies the target matches the source. * * @param source the source//from w w w . j ava 2 s . c o m * @param target the target */ @Override protected void checkTarget(File source, File target) throws IOException { assertTrue(target.exists()); assertEquals(source.lastModified(), target.lastModified()); // for pack200 can't do a size comparison as it modifies the jar structure, so compare the jar contents byte[] sourceBytes = getEntry(source, "source.txt"); byte[] targetBytes = getEntry(target, "source.txt"); assertArrayEquals(sourceBytes, targetBytes); }
From source file:com.snaker.EngineManager.java
public Engine getEngine(String engineName) { Engine result = null;/* w w w . ja v a 2s. c om*/ int index = 0; for (Engine def : engines) { if (def.getName().equalsIgnoreCase(engineName)) { result = def; break; } ++index; } if (result != null) { File f = new File(result.getSourceFile()); if (f.exists()) { if (f.lastModified() > result.getLastModified()) { result = reloadEngine(f); engines.set(index, result); } } else { engines.remove(index); result = null; } } return result; }
From source file:com.virtualparadigm.packman.processor.JPackageManagerOld.java
public static boolean configureOld(File tempDir, Configuration configuration) { logger.info("PackageManager::configure()"); boolean status = true; if (tempDir != null && configuration != null && !configuration.isEmpty()) { VelocityEngine velocityEngine = new VelocityEngine(); Properties vProps = new Properties(); vProps.setProperty("resource.loader", "string"); vProps.setProperty("string.resource.loader.class", "org.apache.velocity.runtime.resource.loader.StringResourceLoader"); velocityEngine.init(vProps);// ww w.ja va 2 s . co m Template template = null; VelocityContext velocityContext = JPackageManagerOld.createVelocityContext(configuration); StringResourceRepository stringResourceRepository = StringResourceLoader.getRepository(); String templateContent = null; StringWriter stringWriter = null; long lastModified; Collection<File> patchFiles = FileUtils.listFiles( new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.PATCH_DIR_NAME + "/" + JPackageManagerOld.PATCH_FILES_DIR_NAME), TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY); if (patchFiles != null) { for (File pfile : patchFiles) { logger.debug(" processing patch fileset file: " + pfile.getAbsolutePath()); try { lastModified = pfile.lastModified(); templateContent = FileUtils.readFileToString(pfile); if (templateContent.matches("(\\$)(\\{)([^\\}]*)(\\:)([^\\{]*)(\\})")) { System.out.println(" converting $ to #"); } templateContent = templateContent.replaceAll("#", "\\#"); templateContent = templateContent.replaceAll("(\\$)(\\{)([^\\}]*)(\\:)([^\\{]*)(\\})", "#$2$3$4$5$6"); stringResourceRepository.putStringResource(JPackageManagerOld.CURRENT_TEMPLATE_NAME, templateContent); stringWriter = new StringWriter(); template = velocityEngine.getTemplate(JPackageManagerOld.CURRENT_TEMPLATE_NAME); template.merge(velocityContext, stringWriter); templateContent = stringWriter.toString(); if (templateContent.matches("(#)(\\{)([^\\}]*)(\\:)([^\\{]*)(\\})")) { System.out.println(" converting # back to $"); } templateContent = templateContent.replaceAll("(#)(\\{)([^\\}]*)(\\:)([^\\{]*)(\\})", "\\$$2$3$4$5$6"); templateContent = templateContent.replaceAll("\\#", "#"); FileUtils.writeStringToFile(pfile, templateContent); pfile.setLastModified(lastModified); } catch (Exception e) { e.printStackTrace(); } } } Collection<File> scriptFiles = FileUtils.listFiles( new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.AUTORUN_DIR_NAME), TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY); if (scriptFiles != null) { for (File scriptfile : scriptFiles) { logger.debug(" processing script file: " + scriptfile.getAbsolutePath()); try { lastModified = scriptfile.lastModified(); templateContent = FileUtils.readFileToString(scriptfile); templateContent = templateContent.replaceAll("#", "\\#"); templateContent = templateContent.replaceAll("(\\$)(\\{)([^\\}]*)(\\:)([^\\{]*)(\\})", "#$2$3$4$5$6"); stringResourceRepository.putStringResource(JPackageManagerOld.CURRENT_TEMPLATE_NAME, templateContent); stringWriter = new StringWriter(); template = velocityEngine.getTemplate(JPackageManagerOld.CURRENT_TEMPLATE_NAME); template.merge(velocityContext, stringWriter); templateContent = stringWriter.toString(); templateContent = templateContent.replaceAll("(#)(\\{)([^\\}]*)(\\:)([^\\{]*)(\\})", "\\$$2$3$4$5$6"); templateContent = templateContent.replaceAll("\\#", "#"); FileUtils.writeStringToFile(scriptfile, templateContent); scriptfile.setLastModified(lastModified); } catch (Exception e) { e.printStackTrace(); } } } } return status; }
From source file:io.stallion.assets.AssetsController.java
public Long getTimeStampForAssetFile(String path) { String filePath = Context.settings().getTargetFolder() + "/assets/" + path; if (getTimeStampByPath().containsKey(filePath)) { Long ts = getTimeStampByPath().get(filePath); if (ts > 0) { return ts; }//ww w .j a v a 2s. com } Path pathObj = FileSystems.getDefault().getPath(filePath); File file = new File(filePath); Long ts = file.lastModified(); getTimeStampByPath().put(filePath, ts); return ts; }
From source file:com.github.neio.filesystem.paths.TestFilePath.java
@Test public void testTouch() throws InterruptedException, IOException { File testFile = new File(testDir, "testFile"); FileUtils.writeStringToFile(testFile, "Hello World"); long initialTime = testFile.lastModified(); TimeUnit.SECONDS.sleep(1);//ww w.j a va 2 s. c o m new FilePath("./testTempDir/testFile").touch(); Assert.assertTrue(initialTime < testFile.lastModified()); }
From source file:com.wikitude.phonegap.WikitudePlugin.java
private static int clearCacheFolder(final File dir, final int numDays) { int deletedFiles = 0; if (dir != null && dir.isDirectory()) { try {/*from w w w. jav a 2s . co m*/ for (File child : dir.listFiles()) { //first delete subdirectories recursively if (child.isDirectory()) { deletedFiles += clearCacheFolder(child, numDays); } //then delete the files and subdirectories in this dir //only empty directories can be deleted, so subdirs have been done first if (child.lastModified() < new Date().getTime() - numDays * DateUtils.DAY_IN_MILLIS) { if (child.delete()) { deletedFiles++; } } } } catch (Exception e) { e.printStackTrace(); } } return deletedFiles; }