List of usage examples for java.io File setLastModified
public boolean setLastModified(long time)
From source file:org.fornax.toolsupport.sculptor.maven.plugin.GraphvizMojoTest.java
public void testChangedDotFilesUpdatedImageFile() throws Exception { GraphvizMojo mojo = createMojo(createProject("test2")); File dotFile = new File(mojo.getProject().getBasedir(), GENERATED_FILE); dotFile.setLastModified(System.currentTimeMillis() + 1000); Set<String> changedDotFiles = mojo.getChangedDotFiles(); assertNotNull(changedDotFiles);/*from w ww .j av a 2s.c o m*/ assertEquals(3, changedDotFiles.size()); }
From source file:org.candlepin.pinsetter.tasks.ExportCleanerTest.java
@Test public void execute() throws Exception { File baseDir = new File("/tmp/syncdirtest"); baseDir.mkdir();//from w w w. ja v a2 s. c om try { File tmp1 = new File(baseDir.getAbsolutePath(), "test-dir-1"); tmp1.mkdir(); tmp1.setLastModified(Util.yesterday().getTime() - 1000); File tmp2 = new File(baseDir.getAbsolutePath(), "test-dir-2"); tmp2.mkdir(); tmp2.setLastModified(Util.yesterday().getTime() - 1000); File tmp3 = new File(baseDir.getAbsolutePath(), "test-dir-3"); tmp3.mkdir(); when(config.getString(eq(ConfigProperties.SYNC_WORK_DIR))).thenReturn(baseDir.getPath()); cleaner.execute(null); assert (!tmp1.exists()); assert (!tmp2.exists()); assert (tmp3.exists()); } finally { FileUtils.deleteDirectory(baseDir); } }
From source file:org.sonar.runner.impl.TempCleaningTest.java
@Test public void should_clean() throws Exception { File dir = temp.newFolder();/* w w w . j a v a2 s .c o m*/ File oldBatch = new File(dir, "sonar-runner-batch656.jar"); FileUtils.write(oldBatch, "foo"); oldBatch.setLastModified(System.currentTimeMillis() - 3 * TempCleaning.ONE_DAY_IN_MILLISECONDS); File youngBatch = new File(dir, "sonar-runner-batch123.jar"); FileUtils.write(youngBatch, "foo"); File doNotDelete = new File(dir, "jacoco.txt"); FileUtils.write(doNotDelete, "foo"); assertThat(oldBatch).exists(); assertThat(youngBatch).exists(); assertThat(doNotDelete).exists(); new TempCleaning(dir, mock(Logger.class)).clean(); assertThat(oldBatch).doesNotExist(); assertThat(youngBatch).exists(); assertThat(doNotDelete).exists(); }
From source file:info.magnolia.ui.framework.command.CleanTempFilesCommandTest.java
@Test public void testCleanTempFilesOlderThan12Hours() throws Exception { //GIVEN// ww w . j a v a2s . co m long lastModified = System.currentTimeMillis() - 13 * 60 * 60 * 1000; File file1 = new File("tmp/file1"); file1.createNewFile(); file1.setLastModified(lastModified); File file2 = new File("tmp/file2"); file2.createNewFile(); File file3 = new File("tmp/file3"); file3.createNewFile(); File file4 = new File("tmp/file4"); file4.createNewFile(); file4.setLastModified(lastModified); //WHEN cleanTempFilesCommand.execute(null); List<File> files = Arrays.asList(tmpDir.listFiles()); //THEN assertFalse(files.contains(file1)); assertTrue(files.contains(file2)); assertTrue(files.contains(file3)); assertFalse(files.contains(file4)); }
From source file:WarUtil.java
/** * WAR???????????//from w ww.jav a 2 s . com * * @param warFile * @param directory * @throws IOException */ public static void extractWar(File warFile, File directory) throws IOException { try { long timestamp = warFile.lastModified(); File warModifiedTimeFile = new File(directory, LAST_MODIFIED_FILE); long lastModified = readLastModifiled(warModifiedTimeFile); if (timestamp == lastModified) { // log.info("war file " + warFile.getName() + " not modified."); return; } if (directory.exists()) { // IOUtil.forceRemoveDirectory(directory); directory.mkdir(); } // log.info("war extract start. warfile=" + warFile.getName()); JarInputStream jin = new JarInputStream(new BufferedInputStream(new FileInputStream(warFile))); JarEntry entry = null; while ((entry = jin.getNextJarEntry()) != null) { File file = new File(directory, entry.getName()); if (entry.isDirectory()) { if (!file.exists()) { file.mkdirs(); } } else { File dir = new File(file.getParent()); if (!dir.exists()) { dir.mkdirs(); } FileOutputStream fout = null; try { fout = new FileOutputStream(file); ResourceUtil.copyStream(jin, fout); } finally { fout.flush(); fout.close(); fout = null; } if (entry.getTime() >= 0) { file.setLastModified(entry.getTime()); } } } writeLastModifiled(warModifiedTimeFile, timestamp); //log.info("war extract success. lastmodified=" + timestamp); } catch (IOException ioe) { //log.info("war extract fail."); throw ioe; } }
From source file:com.jalios.ejpt.sync.utils.IOUtil.java
/** * Copy f1 into f2 (mkdirs for f2)//from w ww .j a v a 2s . com * * @param f1 * the source file * @param f2 * the target file * @throws IOException */ public static void copyFile(File f1, File f2) throws IOException { if (f1 == null || f2 == null) { throw new IllegalArgumentException("f1 and f2 arguments must not be null"); } // Create target directories if (f2.getParentFile() != null) { f2.getParentFile().mkdirs(); } // Copy InputStream input = null; OutputStream output = null; try { input = new FileInputStream(f1); output = new FileOutputStream(f2); IOUtils.copy(input, output); } finally { if (input != null) { try { input.close(); } catch (IOException ex) { } } if (output != null) { try { output.close(); } catch (IOException ex) { } } } f2.setLastModified(f1.lastModified()); }
From source file:org.silverpeas.core.io.temp.LastModifiedDateFileTask.java
private void setLastModifiedDate(final File file, final long lastModifiedDate) { boolean isOk = file.setLastModified(lastModifiedDate); if (!isOk) {/*from www.j av a 2s . c o m*/ SilverLogger.getLogger(this).warn("Unable set last modification date to file " + file.getPath()); } }
From source file:org.dbgl.util.FileUtils.java
public static void fileSetLastModified(final File file, final long time) { if (!file.setLastModified(time)) { System.err.println(Settings.getInstance().msg("general.error.setlastmodifiedfile", new Object[] { file.getPath() })); }/*from ww w.j a v a2 s . com*/ }
From source file:com.michelin.cio.hudson.plugins.copytoslave.MyFilePath.java
/** * Full copy/paste of Hudson's {@link FilePath#readFromTar} method with * some tweaking (mainly the flatten behavior). * * @see hudson.FilePath#readFromTar(java.lang.String, java.io.File, java.io.InputStream) *//*from w ww . j a va 2s .c o m*/ public static void readFromTar(File baseDir, boolean flatten, InputStream in) throws IOException { Chmod chmodTask = null; // HUDSON-8155 TarInputStream t = new TarInputStream(in); try { TarEntry tarEntry; while ((tarEntry = t.getNextEntry()) != null) { File f = null; if (!flatten || (!tarEntry.getName().contains("/") && !tarEntry.getName().contains("\\"))) { f = new File(baseDir, tarEntry.getName()); } else { String fileName = StringUtils.substringAfterLast(tarEntry.getName(), "/"); if (StringUtils.isBlank(fileName)) { fileName = StringUtils.substringAfterLast(tarEntry.getName(), "\\"); } f = new File(baseDir, fileName); } // dir processing if (!flatten && tarEntry.isDirectory()) { f.mkdirs(); } // file processing else { if (!flatten && f.getParentFile() != null) { f.getParentFile().mkdirs(); } IOUtils.copy(t, f); f.setLastModified(tarEntry.getModTime().getTime()); // chmod int mode = tarEntry.getMode() & 0777; if (mode != 0 && !Functions.isWindows()) // be defensive try { LIBC.chmod(f.getPath(), mode); } catch (NoClassDefFoundError ncdfe) { // be defensive. see http://www.nabble.com/-3.0.6--Site-copy-problem%3A-hudson.util.IOException2%3A--java.lang.NoClassDefFoundError%3A-Could-not-initialize-class--hudson.util.jna.GNUCLibrary-td23588879.html } catch (UnsatisfiedLinkError ule) { // HUDSON-8155: use Ant's chmod task if (chmodTask == null) { chmodTask = new Chmod(); } chmodTask.setProject(new Project()); chmodTask.setFile(f); chmodTask.setPerm(Integer.toOctalString(mode)); chmodTask.execute(); } } } } catch (IOException e) { throw new IOException2("Failed to extract to " + baseDir.getAbsolutePath(), e); } finally { t.close(); } }
From source file:com.novoda.imageloader.core.file.FileUtilTest.java
private File createFile(String name, long lastModified) { try {/*from w w w .ja v a 2 s . co m*/ File f1 = new File(cacheDir, name + ".tmp"); FileUtils.write(f1, name); if (lastModified != -1) { f1.setLastModified(lastModified); } return f1; } catch (Exception e) { Assert.fail("Can't crete file for the test" + e.getMessage()); throw new RuntimeException("Can't crete file for the test " + e.getMessage()); } }