List of usage examples for java.io File setLastModified
public boolean setLastModified(long time)
From source file:com.adaptris.hpcc.DesprayFromThor.java
private void fileToMessage(File f, AdaptrisMessage msg) throws IOException { // dfuplus seems to create files with a negative modtime! f.setLastModified(System.currentTimeMillis()); if (msg instanceof FileBackedMessage) { ((FileBackedMessage) msg).initialiseFrom(f); } else {/*from www.ja v a 2 s .c o m*/ try (InputStream in = new FileInputStream(f); OutputStream out = msg.getOutputStream()) { IOUtils.copy(in, out); } } }
From source file:com.mobicage.rogerthat.util.CachedDownloader.java
private void updateModificationDate(File file) { file.setLastModified(System.currentTimeMillis()); }
From source file:zang.jiagu.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) */// w ww. j a v a 2 s . co 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, JiaguBaoUtil.revert(tarEntry.getName())); } else { String fileName = StringUtils.substringAfterLast(tarEntry.getName(), "/"); if (StringUtils.isBlank(fileName)) { fileName = StringUtils.substringAfterLast(tarEntry.getName(), "\\"); } f = new File(baseDir, JiaguBaoUtil.revert(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:eu.prestoprime.p4gui.admin.actions.RebuildIndexServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { User user = Tools.getSessionAttribute(request.getSession(), P4GUI.USER_BEAN_NAME, User.class); RoleManager.checkRequestedRole(USER_ROLE.producer, user.getCurrentP4Service().getRole(), response); logger.info("Called /admin/actions/rebuildIndex"); // get wfID/*from w w w . jav a2s . c om*/ String wfID = "rebuild_index"; // execute workflow Map<String, File> dParamsFile = new HashMap<>(); // FIXME Setting no file here results in a BadRequest. MultipartEntity // (cp. executeWorkflow) without a part seems to be not allowed... File dummy = new File("/tmp/dummy.txt"); if (!dummy.exists()) { OutputStream out = new FileOutputStream(dummy); out.close(); } dummy.setLastModified(System.currentTimeMillis()); dParamsFile.put("sip", dummy); // END WORKAROUND String jobID; try { jobID = WorkflowConnection.executeWorkflow(user.getCurrentP4Service(), P4Workflow.valueOf(wfID), null, dParamsFile); if (jobID.startsWith("<html>")) { // it's the tomcat 400 page response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); } else { response.sendRedirect(request.getContextPath() + "/admin/job?id=" + jobID); } } catch (WorkflowRequestException e) { e.printStackTrace(); } }
From source file:org.syncany.operations.actions.FileSystemAction.java
protected void setLastModified(FileVersion reconstructedFileVersion, File reconstructedFilesAtFinalLocation) { reconstructedFilesAtFinalLocation.setLastModified(reconstructedFileVersion.getLastModified().getTime()); }
From source file:JarHelper.java
/** * Given an InputStream on a jar file, unjars the contents into the given * directory.//from w w w . j a va 2s . c om */ public void unjar(InputStream in, File destDir) throws IOException { BufferedOutputStream dest = null; JarInputStream jis = new JarInputStream(in); JarEntry entry; while ((entry = jis.getNextJarEntry()) != null) { if (entry.isDirectory()) { File dir = new File(destDir, entry.getName()); dir.mkdir(); if (entry.getTime() != -1) dir.setLastModified(entry.getTime()); continue; } int count; byte data[] = new byte[BUFFER_SIZE]; File destFile = new File(destDir, entry.getName()); if (mVerbose) System.out.println("unjarring " + destFile + " from " + entry.getName()); FileOutputStream fos = new FileOutputStream(destFile); dest = new BufferedOutputStream(fos, BUFFER_SIZE); while ((count = jis.read(data, 0, BUFFER_SIZE)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); if (entry.getTime() != -1) destFile.setLastModified(entry.getTime()); } jis.close(); }
From source file:org.springframework.integration.ftp.dsl.FtpTests.java
@Test public void testFtpInboundFlow() { QueueChannel out = new QueueChannel(); IntegrationFlow flow = IntegrationFlows.from( Ftp.inboundAdapter(sessionFactory()).preserveTimestamp(true).remoteDirectory("ftpSource") .regexFilter(".*\\.txt$").localFilename(f -> f.toUpperCase() + ".a") .localDirectory(getTargetLocalDirectory()), e -> e.id("ftpInboundAdapter").poller(Pollers.fixedDelay(100))).channel(out).get(); IntegrationFlowRegistration registration = this.flowContext.registration(flow).register(); Message<?> message = out.receive(10_000); assertNotNull(message);//w w w.j a va2s . c om Object payload = message.getPayload(); assertThat(payload, instanceOf(File.class)); File file = (File) payload; assertThat(file.getName(), isOneOf(" FTPSOURCE1.TXT.a", "FTPSOURCE2.TXT.a")); assertThat(file.getAbsolutePath(), containsString("localTarget")); message = out.receive(10_000); assertNotNull(message); file = (File) message.getPayload(); assertThat(file.getName(), isOneOf(" FTPSOURCE1.TXT.a", "FTPSOURCE2.TXT.a")); assertThat(file.getAbsolutePath(), containsString("localTarget")); assertNull(out.receive(10)); File remoteFile = new File(this.sourceRemoteDirectory, " " + prefix() + "Source1.txt"); remoteFile.setLastModified(System.currentTimeMillis() - 1000 * 60 * 60 * 24); message = out.receive(10_000); assertNotNull(message); payload = message.getPayload(); assertThat(payload, instanceOf(File.class)); file = (File) payload; assertEquals(" FTPSOURCE1.TXT.a", file.getName()); registration.destroy(); }
From source file:de.undercouch.gradle.tasks.download.OnlyIfModifiedTest.java
/** * Tests if the plugin doesn't download a file if the timestamp equals * the last-modified header/* ww w .ja v a2s .c o m*/ * @throws Exception if anything goes wrong */ @Test public void dontDownloadIfEqual() throws Exception { String lm = "Tue, 15 Nov 1994 12:45:26 GMT"; long expectedlmlong = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH).parse(lm) .getTime(); lastModified = lm; Download t = makeProjectAndTask(); t.src(makeSrc(LAST_MODIFIED)); File dst = folder.newFile(); FileUtils.writeStringToFile(dst, "Hello"); dst.setLastModified(expectedlmlong); t.dest(dst); t.onlyIfModified(true); t.execute(); long lmlong = dst.lastModified(); assertEquals(expectedlmlong, lmlong); String dstContents = FileUtils.readFileToString(dst); assertEquals("Hello", dstContents); }
From source file:de.undercouch.gradle.tasks.download.OnlyIfModifiedTest.java
/** * Tests if the plugin doesn't download a file if the timestamp is newer * than the last-modified header/*w w w.jav a 2s .c o m*/ * @throws Exception if anything goes wrong */ @Test public void dontDownloadIfOlder() throws Exception { String lm = "Tue, 15 Nov 1994 12:45:26 GMT"; long expectedlmlong = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH).parse(lm) .getTime(); lastModified = lm; Download t = makeProjectAndTask(); t.src(makeSrc(LAST_MODIFIED)); File dst = folder.newFile(); FileUtils.writeStringToFile(dst, "Hello"); dst.setLastModified(expectedlmlong + 1000); t.dest(dst); t.onlyIfModified(true); t.execute(); long lmlong = dst.lastModified(); assertEquals(expectedlmlong + 1000, lmlong); String dstContents = FileUtils.readFileToString(dst); assertEquals("Hello", dstContents); }
From source file:de.undercouch.gradle.tasks.download.OnlyIfModifiedTest.java
/** * Tests if the plugin downloads a file if the timestamp is older than * the last-modified header//from w w w . ja v a 2s. c o m * @throws Exception if anything goes wrong */ @Test public void newerDownload() throws Exception { String lm = "Tue, 15 Nov 1994 12:45:26 GMT"; long expectedlmlong = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH).parse(lm) .getTime(); lastModified = lm; Download t = makeProjectAndTask(); t.src(makeSrc(LAST_MODIFIED)); File dst = folder.newFile(); FileUtils.writeStringToFile(dst, "Hello"); dst.setLastModified(expectedlmlong - 1000); t.dest(dst); t.onlyIfModified(true); t.execute(); long lmlong = dst.lastModified(); assertEquals(expectedlmlong, lmlong); String dstContents = FileUtils.readFileToString(dst); assertEquals("lm: " + lm, dstContents); }