List of usage examples for java.io File setLastModified
public boolean setLastModified(long time)
From source file:stroom.streamstore.server.fs.FileSystemUtil.java
public static boolean updateLastModified(final Collection<File> files, final long lastModified) { boolean allOk = true; for (File file : files) { allOk &= file.setLastModified(lastModified); }/*from www . j ava 2s .c o m*/ return allOk; }
From source file:com.axelor.apps.tool.net.MyFtp.java
public static void getDataFiles(String server, String username, String password, String folder, String destinationFolder, Calendar start, Calendar end) { try {/*w w w.j a v a 2 s. c om*/ // Connect and logon to FTP Server FTPClient ftp = new FTPClient(); ftp.connect(server); ftp.login(username, password); // List the files in the directory ftp.changeWorkingDirectory(folder); FTPFile[] files = ftp.listFiles(); for (int i = 0; i < files.length; i++) { Date fileDate = files[i].getTimestamp().getTime(); if (fileDate.compareTo(start.getTime()) >= 0 && fileDate.compareTo(end.getTime()) <= 0) { // Download a file from the FTP Server File file = new File(destinationFolder + File.separator + files[i].getName()); FileOutputStream fos = new FileOutputStream(file); ftp.retrieveFile(files[i].getName(), fos); fos.close(); file.setLastModified(fileDate.getTime()); } } // Logout from the FTP Server and disconnect ftp.logout(); ftp.disconnect(); } catch (Exception e) { LOG.error(e.getMessage()); } }
From source file:Utils.java
/** * unpack a segment from a zip//from www. ja v a 2 s. c o m * * @param addsi * @param packetStream * @param version */ public static void unpack(InputStream source, File destination) throws IOException { ZipInputStream zin = new ZipInputStream(source); ZipEntry zipEntry = null; FileOutputStream fout = null; byte[] buffer = new byte[4096]; while ((zipEntry = zin.getNextEntry()) != null) { long ts = zipEntry.getTime(); // the zip entry needs to be a full path from the // searchIndexDirectory... hence this is correct File f = new File(destination, zipEntry.getName()); f.getParentFile().mkdirs(); fout = new FileOutputStream(f); int len; while ((len = zin.read(buffer)) > 0) { fout.write(buffer, 0, len); } zin.closeEntry(); fout.close(); f.setLastModified(ts); } fout.close(); }
From source file:com.netflix.spinnaker.clouddriver.appengine.artifacts.StorageUtils.java
public static void untarStreamToPath(InputStream inputStream, String basePath) throws IOException { class DirectoryTimestamp { public DirectoryTimestamp(File d, long m) { directory = d;//from w w w . j av a2 s.com millis = m; } public File directory; public long millis; } ; // Directories come in hierarchical order within the stream, but // we need to set their timestamps after their children have been written. Stack<DirectoryTimestamp> directoryStack = new Stack<DirectoryTimestamp>(); File baseDirectory = new File(basePath); baseDirectory.mkdir(); TarArchiveInputStream tarStream = new TarArchiveInputStream(inputStream); for (TarArchiveEntry entry = tarStream.getNextTarEntry(); entry != null; entry = tarStream .getNextTarEntry()) { File target = new File(baseDirectory, entry.getName()); if (entry.isDirectory()) { directoryStack.push(new DirectoryTimestamp(target, entry.getModTime().getTime())); continue; } writeStreamToFile(tarStream, target); target.setLastModified(entry.getModTime().getTime()); } while (!directoryStack.empty()) { DirectoryTimestamp info = directoryStack.pop(); info.directory.setLastModified(info.millis); } tarStream.close(); }
From source file:org.jumpmind.util.AppUtils.java
public static void unzip(InputStream in, File toDir) { try {//from w ww . j a v a 2s.com ZipInputStream is = new ZipInputStream(in); ZipEntry entry = null; do { entry = is.getNextEntry(); if (entry != null) { if (entry.isDirectory()) { File dir = new File(toDir, entry.getName()); dir.mkdirs(); dir.setLastModified(entry.getTime()); } else { File file = new File(toDir, entry.getName()); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); file.getParentFile().setLastModified(entry.getTime()); } FileOutputStream fos = new FileOutputStream(file); try { IOUtils.copy(is, fos); file.setLastModified(entry.getTime()); } finally { IOUtils.closeQuietly(fos); } } } } while (entry != null); } catch (IOException e) { throw new IoException(e); } }
From source file:org.apache.kylin.common.util.ZipFileUtils.java
public static void decompressZipfileToDirectory(String zipFileName, File outputFolder) throws IOException { ZipInputStream zipInputStream = null; try {//from w w w .j a va2s .c om zipInputStream = new ZipInputStream(new FileInputStream(zipFileName)); ZipEntry zipEntry = null; while ((zipEntry = zipInputStream.getNextEntry()) != null) { logger.info("decompressing " + zipEntry.getName() + " is directory:" + zipEntry.isDirectory() + " available: " + zipInputStream.available()); File temp = new File(outputFolder, zipEntry.getName()); if (zipEntry.isDirectory()) { temp.mkdirs(); } else { temp.getParentFile().mkdirs(); temp.createNewFile(); temp.setLastModified(zipEntry.getTime()); FileOutputStream outputStream = new FileOutputStream(temp); try { IOUtils.copy(zipInputStream, outputStream); } finally { IOUtils.closeQuietly(outputStream); } } } } finally { IOUtils.closeQuietly(zipInputStream); } }
From source file:org.nuxeo.ecm.core.blob.binary.LocalBinaryManager.java
/** * Sets the last modification date to now on a file * * @param file the file/* ww w . j av a2s .c om*/ */ public static void touch(File file) { long time = System.currentTimeMillis(); if (file.setLastModified(time)) { // ok return; } if (!file.canWrite()) { // cannot write -> stop won't be able to delete anyway return; } try { // Windows: the file may be open for reading // workaround found by Thomas Mueller, see JCR-2872 RandomAccessFile r = new RandomAccessFile(file, "rw"); try { r.setLength(r.length()); } finally { r.close(); } } catch (IOException e) { log.error("Cannot set last modified for file: " + file, e); } }
From source file:com.opoopress.maven.plugins.plugin.zip.ZipUtils.java
public static void unzipFileToDirectory(File file, File destDir, boolean keepTimestamp) throws IOException { // create output directory if it doesn't exist if (!destDir.exists()) destDir.mkdirs();/* ww w. j a v a 2s .co m*/ ZipFile zipFile = new ZipFile(file); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.isDirectory()) { new File(destDir, entry.getName()).mkdirs(); continue; } InputStream inputStream = zipFile.getInputStream(entry); File destFile = new File(destDir, entry.getName()); System.out.println("Unzipping to " + destFile.getAbsolutePath()); FileUtils.copyInputStreamToFile(inputStream, destFile); IOUtils.closeQuietly(inputStream); if (keepTimestamp) { long time = entry.getTime(); if (time > 0) { destFile.setLastModified(time); } } } zipFile.close(); }
From source file:org.apache.flink.runtime.testutils.TestJvmProcess.java
public static void touchFile(File file) throws IOException { if (!file.exists()) { new FileOutputStream(file).close(); }//from w w w .j a v a 2 s. c om if (!file.setLastModified(System.currentTimeMillis())) { throw new IOException("Could not touch the file."); } }
From source file:com.threecrickets.sincerity.util.IoUtil.java
/** * Updates a file's last-modified timestamp. * <p>/*ww w .ja va 2 s.c o m*/ * If the file doesn't exist, it is created as an empty file, including * necessary parent directories. * * @param file * The file * @throws IOException * In case of an I/O error */ public static void touch(File file) throws IOException { if (file.exists()) file.setLastModified(System.currentTimeMillis()); else { File parent = file.getParentFile(); if (parent != null) parent.mkdirs(); file.createNewFile(); } }