List of usage examples for java.io File setLastModified
public boolean setLastModified(long time)
From source file:com.cazcade.billabong.store.impl.FileBasedBinaryStore.java
@Override protected void addToMap(String storeKey, InputStream data) { //Create file File storeFile = new File(storeDirectory, storeKey); try {/*from w w w. j a v a 2s. com*/ if (data != null) { FileOutputStream outputStream = new FileOutputStream(storeFile, false); try { IOUtils.copy(data, outputStream); } finally { outputStream.close(); } storeFile.setLastModified(dateHelper.current().getTime()); //add entry to map. map.put(storeKey, new FileBinaryStoreEntry(storeFile)); } else { map.remove(storeKey); storeFile.delete(); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.adaptris.core.fs.NonDeletingFsConsumerTest.java
private void touch(List<File> files) throws IOException { for (File f : files) { f.setLastModified(System.currentTimeMillis()); }/*w w w .j a va 2 s . com*/ }
From source file:com.ecyrd.jspwiki.util.ProviderConverter.java
protected void convert() throws WikiException, IOException { Properties props = new Properties(); props.setProperty(WikiEngine.PROP_APPNAME, "JSPWikiConvert"); props.setProperty(AbstractFileProvider.PROP_PAGEDIR, m_rcsSourceDir); props.setProperty(PageManager.PROP_PAGEPROVIDER, "RCSFileProvider"); props.setProperty(PageManager.PROP_USECACHE, "false"); props.setProperty("log4j.appender.outlog", "org.apache.log4j.ConsoleAppender"); props.setProperty("log4j.appender.outlog.layout", "org.apache.log4j.PatternLayout"); props.setProperty("jspwiki.useLucene", "false"); props.setProperty("log4j.rootCategory", "INFO,outlog"); WikiEngine engine = new WikiEngine(props); WikiPageProvider sourceProvider = engine.getPageManager().getProvider(); File tmpDir = new File(SystemUtils.JAVA_IO_TMPDIR, "converter-tmp"); props.setProperty(AbstractFileProvider.PROP_PAGEDIR, tmpDir.getAbsolutePath()); WikiPageProvider destProvider = new VersioningFileProvider(); destProvider.initialize(engine, props); Collection allPages = sourceProvider.getAllPages(); int idx = 1;/*w w w . j av a2 s. co m*/ for (Iterator i = allPages.iterator(); i.hasNext();) { WikiPage p = (WikiPage) i.next(); System.out.println("Converting page: " + p.getName() + " (" + idx + "/" + allPages.size() + ")"); List pageHistory = engine.getVersionHistory(p.getName()); for (ListIterator v = pageHistory.listIterator(pageHistory.size()); v.hasPrevious();) { WikiPage pv = (WikiPage) v.previous(); String text = engine.getPureText(pv.getName(), pv.getVersion()); destProvider.putPageText(pv, text); } // // Do manual setting now // for (Iterator v = pageHistory.iterator(); v.hasNext();) { WikiPage pv = (WikiPage) v.next(); File f = new File(tmpDir, "OLD"); f = new File(f, mangleName(pv.getName())); f = new File(f, pv.getVersion() + ".txt"); System.out .println(" Setting old version " + pv.getVersion() + " to date " + pv.getLastModified()); f.setLastModified(pv.getLastModified().getTime()); } idx++; } tmpDir.delete(); }
From source file:tests.unit.util.file.FileChangeMonitorTestCase.java
/** * @throws Exception/* www.java 2 s .c o m*/ */ public void testFileChange() throws Exception { TestListener tl = new TestListener(TEST_FILE_1); File f1 = new File(TEST_FILE_1); f1.createNewFile(); FileChangeMonitor.addFileChangeListener(tl, TEST_FILE_1); assertFalse("Resource " + TEST_FILE_1 + " already modified", tl.isChanged()); Thread.sleep(1000); f1.setLastModified(System.currentTimeMillis()); Thread.sleep(6000); assertTrue("Resource " + TEST_FILE_1 + " modified", tl.isChanged()); }
From source file:com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScannerZipInstaller.java
private File retrieveVersionFile(File scannerExpansionDirectory) throws IOException { File versionFile = new File(scannerExpansionDirectory, ScannerZipInstaller.VERSION_FILENAME); if (!versionFile.exists()) { logger.info("The version file has not been created yet so creating it now."); versionFile.createNewFile();//from w ww . java2s.c om versionFile.setLastModified(0L); } return versionFile; }
From source file:org.eclipse.flux.cloudfoundry.deployment.service.DownloadProject.java
public void getProjectResponse(JSONObject response) { try {// w w w.j ava2s . c o m final String responseProject = response.getString("project"); final String responseUser = response.getString("username"); final JSONArray files = response.getJSONArray("files"); if (this.username.equals(responseUser)) { System.out.println("======== downloadproject createdirs ====="); for (int i = 0; i < files.length(); i++) { JSONObject resource = files.getJSONObject(i); System.out.println("resource = " + resource); String resourcePath = resource.getString("path"); long timestamp = resource.getLong("timestamp"); String type = resource.optString("type"); if (type.equals("folder")) { if (resourcePath.isEmpty()) { project.setLastModified(timestamp); } else { File folder = new File(project, resourcePath); if (!folder.exists()) { folder.mkdirs(); } folder.setLastModified(timestamp); } } else if (type.equals("file")) { requestedFileCount.incrementAndGet(); } } System.out.println("======== downloadproject request resources ====="); for (int i = 0; i < files.length(); i++) { JSONObject resource = files.getJSONObject(i); String resourcePath = resource.getString("path"); String type = resource.optString("type"); if (type.equals("file")) { JSONObject message = new JSONObject(); message.put("callback_id", callbackID); message.put("username", this.username); message.put("project", responseProject); message.put("resource", resourcePath); System.out.println("requesting: " + resource); messagingConnector.send("getResourceRequest", message); } } } } catch (Exception e) { e.printStackTrace(); this.messagingConnector.removeMessageHandler(projectResponseHandler); this.messagingConnector.removeMessageHandler(resourceResponseHandler); this.completionCallback.downloadFailed(); } }
From source file:phex.utils.FileUtils.java
/** * From Apache Jakarta Commons IO./*from w w w .ja v a2 s .c o m*/ * * Internal copy file method. * * @param srcFile the validated source file, not null * @param destFile the validated destination file, not null * @param preserveFileDate whether to preserve the file date * @throws IOException if an error occurs */ private static void doCopyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException { if (destFile.exists() && destFile.isDirectory()) { throw new IOException("Destination '" + destFile + "' exists but is a directory"); } FileChannel input = new FileInputStream(srcFile).getChannel(); try { FileChannel output = new FileOutputStream(destFile).getChannel(); try { output.transferFrom(input, 0, input.size()); } finally { IOUtil.closeQuietly(output); } } finally { IOUtil.closeQuietly(input); } if (srcFile.length() != destFile.length()) { throw new IOException("Failed to copy full contents from '" + srcFile + "' to '" + destFile + "'"); } if (preserveFileDate) { destFile.setLastModified(srcFile.lastModified()); } }
From source file:org.opencms.cache.CmsVfsNameBasedDiskCache.java
/** * Returns the content of the requested file in the disk cache, or <code>null</code> if the * file is not found in the cache, or is found but outdated.<p> * * @param rfsName the file RFS name to look up in the cache * * @return the content of the requested file in the disk cache, or <code>null</code> *///from w ww . j av a2s .c o m public byte[] getCacheContent(String rfsName) { try { File f = new File(rfsName); if (f.exists()) { long age = f.lastModified(); if ((System.currentTimeMillis() - age) > 3600000) { // file has not been touched for 1 hour, touch the file with the current date f.setLastModified(System.currentTimeMillis()); } return CmsFileUtil.readFile(f); } } catch (IOException e) { // unable to read content LOG.debug("Unable to read file " + rfsName, e); } return null; }
From source file:phex.util.FileUtils.java
/** * From Apache Jakarta Commons IO.// ww w .j a v a 2s . com * <p> * Internal copy file method. * * @param srcFile the validated source file, not null * @param destFile the validated destination file, not null * @param preserveFileDate whether to preserve the file date * @throws IOException if an error occurs */ private static void doCopyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException { if (destFile.exists() && destFile.isDirectory()) { throw new IOException("Destination '" + destFile + "' exists but is a directory"); } FileChannel input = new FileInputStream(srcFile).getChannel(); try { FileChannel output = new FileOutputStream(destFile).getChannel(); try { output.transferFrom(input, 0, input.size()); } finally { IOUtil.closeQuietly(output); } } finally { IOUtil.closeQuietly(input); } if (srcFile.length() != destFile.length()) { throw new IOException("Failed to copy full contents from '" + srcFile + "' to '" + destFile + '\''); } if (preserveFileDate) { destFile.setLastModified(srcFile.lastModified()); } }
From source file:com.facebook.buck.util.unarchive.Unzip.java
private void writeZipContents(ZipFile zip, ZipArchiveEntry entry, ProjectFilesystem filesystem, Path target) throws IOException { // Write file try (InputStream is = zip.getInputStream(entry)) { if (entry.isUnixSymlink()) { filesystem.createSymLink(target, filesystem.getPath(new String(ByteStreams.toByteArray(is), Charsets.UTF_8)), /* force */ true); } else {/*from w w w .j a v a 2 s .c o m*/ try (OutputStream out = filesystem.newFileOutputStream(target)) { ByteStreams.copy(is, out); } } } Path filePath = filesystem.resolve(target); File file = filePath.toFile(); // restore mtime for the file file.setLastModified(entry.getTime()); // TODO(simons): Implement what the comment below says we should do. // // Sets the file permissions of the output file given the information in {@code entry}'s // extra data field. According to the docs at // http://www.opensource.apple.com/source/zip/zip-6/unzip/unzip/proginfo/extra.fld there // are two extensions that might support file permissions: Acorn and ASi UNIX. We shall // assume that inputs are not from an Acorn SparkFS. The relevant section from the docs: // // <pre> // The following is the layout of the ASi extra block for Unix. The // local-header and central-header versions are identical. // (Last Revision 19960916) // // Value Size Description // ----- ---- ----------- // (Unix3) 0x756e Short tag for this extra block type ("nu") // TSize Short total data size for this block // CRC Long CRC-32 of the remaining data // Mode Short file permissions // SizDev Long symlink'd size OR major/minor dev num // UID Short user ID // GID Short group ID // (var.) variable symbolic link filename // // Mode is the standard Unix st_mode field from struct stat, containing // user/group/other permissions, setuid/setgid and symlink info, etc. // </pre> // // From the stat man page, we see that the following mask values are defined for the file // permissions component of the st_mode field: // // <pre> // S_ISUID 0004000 set-user-ID bit // S_ISGID 0002000 set-group-ID bit (see below) // S_ISVTX 0001000 sticky bit (see below) // // S_IRWXU 00700 mask for file owner permissions // // S_IRUSR 00400 owner has read permission // S_IWUSR 00200 owner has write permission // S_IXUSR 00100 owner has execute permission // // S_IRWXG 00070 mask for group permissions // S_IRGRP 00040 group has read permission // S_IWGRP 00020 group has write permission // S_IXGRP 00010 group has execute permission // // S_IRWXO 00007 mask for permissions for others // (not in group) // S_IROTH 00004 others have read permission // S_IWOTH 00002 others have write permission // S_IXOTH 00001 others have execute permission // </pre> // // For the sake of our own sanity, we're going to assume that no-one is using symlinks, // but we'll check and throw if they are. // // Before we do anything, we should check the header ID. Pfft! // // Having jumped through all these hoops, it turns out that InfoZIP's "unzip" store the // values in the external file attributes of a zip entry (found in the zip's central // directory) assuming that the OS creating the zip was one of an enormous list that // includes UNIX but not Windows, it first searches for the extra fields, and if not found // falls through to a code path that supports MS-DOS and which stores the UNIX file // attributes in the upper 16 bits of the external attributes field. // // We'll support neither approach fully, but we encode whether this file was executable // via storing 0100 in the fields that are typically used by zip implementations to store // POSIX permissions. If we find it was executable, use the platform independent java // interface to make this unpacked file executable. Set<PosixFilePermission> permissions = MorePosixFilePermissions .fromMode(entry.getExternalAttributes() >> 16); if (permissions.contains(PosixFilePermission.OWNER_EXECUTE) && file.getCanonicalFile().exists()) { MostFiles.makeExecutable(filePath); } }