List of usage examples for java.io File setLastModified
public boolean setLastModified(long time)
From source file:fr.fastconnect.factory.tibco.bw.fcunit.PrepareTestMojo.java
private void removeFileInZipContaining(List<String> contentFilter, File zipFile) throws ZipException, IOException { ZipScanner zs = new ZipScanner(); zs.setSrc(zipFile);/*from w w w . ja v a 2 s . co m*/ String[] includes = { "**/*.process" }; zs.setIncludes(includes); //zs.setCaseSensitive(true); zs.init(); zs.scan(); File originalProjlib = zipFile; // to be overwritten File tmpProjlib = new File(zipFile.getAbsolutePath() + ".tmp"); // to read FileUtils.copyFile(originalProjlib, tmpProjlib); ZipFile listZipFile = new ZipFile(tmpProjlib); ZipInputStream readZipFile = new ZipInputStream(new FileInputStream(tmpProjlib)); ZipOutputStream writeZipFile = new ZipOutputStream(new FileOutputStream(originalProjlib)); ZipEntry zipEntry; boolean keep; while ((zipEntry = readZipFile.getNextEntry()) != null) { keep = true; for (String filter : contentFilter) { keep = keep && !containsString(filter, listZipFile.getInputStream(zipEntry)); } // if (!containsString("<pd:type>com.tibco.pe.core.OnStartupEventSource</pd:type>", listZipFile.getInputStream(zipEntry)) // && !containsString("<pd:type>com.tibco.plugin.jms.JMSTopicEventSource</pd:type>", listZipFile.getInputStream(zipEntry))) { if (keep) { writeZipFile.putNextEntry(zipEntry); int len = 0; byte[] buf = new byte[1024]; while ((len = readZipFile.read(buf)) >= 0) { writeZipFile.write(buf, 0, len); } writeZipFile.closeEntry(); //getLog().info("written"); } else { getLog().info("removed " + zipEntry.getName()); } } writeZipFile.close(); readZipFile.close(); listZipFile.close(); originalProjlib.setLastModified(originalProjlib.lastModified() - 100000); }
From source file:com.liferay.ide.theme.core.util.BuildHelper.java
/** * Copy a file from a to b. Closes the input stream after use. * * @param in//from w w w. ja va 2 s. com * an input stream * @param to * a path to copy to. the directory must already exist * @param ts * timestamp * @throws CoreException * if anything goes wrong */ private void copyFile(InputStream in, IPath to, long ts, IFile mf) throws CoreException { OutputStream out = null; File tempFile = null; File tempFileParentDir = null; try { File file = to.toFile(); // IDE-796 need to make sure temporary file is generated in same directory as file destination so that // file.renameTo() will never fail due to source/destination being on two different file systems if (file != null && file.getParentFile().exists()) { tempFileParentDir = to.toFile().getParentFile(); } else { tempFileParentDir = tempDir; } tempFile = File.createTempFile(TEMPFILE_PREFIX, "." + to.getFileExtension(), tempFileParentDir); //$NON-NLS-1$ out = new FileOutputStream(tempFile); int avail = in.read(buf); while (avail > 0) { out.write(buf, 0, avail); avail = in.read(buf); } out.close(); out = null; moveTempFile(tempFile, file); if (ts != IResource.NULL_STAMP && ts != 0) file.setLastModified(ts); } catch (CoreException e) { throw e; } catch (Exception e) { } finally { if (tempFile != null && tempFile.exists()) tempFile.deleteOnExit(); try { if (in != null) in.close(); } catch (Exception ex) { // ignore } try { if (out != null) out.close(); } catch (Exception ex) { // ignore } } }
From source file:org.openhab.io.dropbox.internal.DropboxSynchronizer.java
private void downloadFile(DbxClient client, Entry<DbxEntry> entry) throws DbxException, IOException { String fqPath = contentDir + entry.metadata.path; File newLocalFile = new File(fqPath); if (entry.metadata.isFolder()) { // create intermediary directories boolean success = newLocalFile.mkdirs(); if (!success) { logger.debug("Didn't create any intermediary directories for '{}'", fqPath); }/*from www. ja v a2 s . c o m*/ } else { // if the parent directory doesn't exist create all intermediary // directorys ... if (!newLocalFile.getParentFile().exists()) { newLocalFile.getParentFile().mkdirs(); } try { FileOutputStream os = new FileOutputStream(newLocalFile); if (!fakeMode) { client.getFile(entry.metadata.path, null, os); } logger.debug("Successfully downloaded file '{}'", fqPath); } catch (FileNotFoundException fnfe) { throw new DbxException("Couldn't write file '" + fqPath + "'", fnfe); } long lastModified = entry.metadata.asFile().lastModified.getTime(); boolean success = newLocalFile.setLastModified(lastModified); if (!success) { logger.debug("Couldn't change attribute 'lastModified' of file '{}'", fqPath); } } }
From source file:org.openhab.io.dropbox.internal.DropboxSynchronizerImpl.java
private void downloadFile(DropboxAPI<WebAuthSession> dropbox, DeltaEntry<Entry> entry) throws DropboxException { String fqPath = contentDir + entry.metadata.path; File newLocalFile = new File(fqPath); if (entry.metadata.isDir) { // create intermediary directories boolean success = newLocalFile.mkdirs(); if (!success) { logger.debug("Didn't create any intermediary directories for '{}'", fqPath); }/*w w w . j a v a 2 s.c om*/ } else { // if the parent directory doesn't exist create all intermediary // directorys ... if (!newLocalFile.getParentFile().exists()) { newLocalFile.getParentFile().mkdirs(); } try { FileOutputStream os = new FileOutputStream(newLocalFile); dropbox.getFile(entry.metadata.path, null, os, null); logger.debug("Successfully downloaded file '{}'", fqPath); } catch (FileNotFoundException fnfe) { throw new DropboxException("Couldn't write file '" + fqPath + "'", fnfe); } } long lastModified = RESTUtility.parseDate(entry.metadata.modified).getTime(); boolean success = newLocalFile.setLastModified(lastModified); if (!success) { logger.debug("Couldn't change attribute 'lastModified' of file '{}'", fqPath); } }
From source file:io.treefarm.plugins.haxe.components.nativeProgram.AbstractNativeProgram.java
private File getDirectory(Artifact artifact) throws Exception { File destinationDirectory = getDestinationDirectoryForArtifact(artifact); if (!destinationDirectory.exists() || artifact.getFile().lastModified() > destinationDirectory.lastModified()) { if (destinationDirectory.exists()) { FileUtils.deleteQuietly(destinationDirectory); }//from ww w . j a va 2s . c o m File unpackDir = new File(outputDirectory, getUniqueArtifactPath() + "-unpack"); if (unpackDir.exists()) FileUtils.deleteQuietly(unpackDir); UnpackHelper unpackHelper = new UnpackHelper() { }; DefaultUnpackMethods unpackMethods = new DefaultUnpackMethods(logger); unpackHelper.unpack(unpackDir, artifact, unpackMethods, null); for (String fileName : unpackDir.list()) { if (artifact.getType().equals("jar")) { fileName = getUniqueArtifactPath(); } File firstFile = new File(unpackDir, fileName); //FileUtils.moveDirectory(firstFile, destinationDirectory); firstFile.renameTo(destinationDirectory); if (!destinationDirectory.exists()) { // manually move using shell call as last ditch Process process = Runtime.getRuntime().exec( "mv " + firstFile.getAbsolutePath() + " " + destinationDirectory.getAbsolutePath()); } break; } if (destinationDirectory.exists()) { destinationDirectory.setLastModified(artifact.getFile().lastModified()); } if (unpackDir.exists()) FileUtils.deleteQuietly(unpackDir); } initialized = true; String directoryPath = destinationDirectory.getAbsolutePath(); // Add current directory to path path.add(directoryPath); return destinationDirectory; }
From source file:org.dcm4chee.proxy.forward.ForwardFiles.java
private void renameFile(ProxyAEExtension proxyAEE, String suffix, File file, String calledAET, Properties prop) {/*from w ww. j av a 2 s. c om*/ File dst; String path = file.getPath(); if (path.endsWith(".snd")) dst = setFileSuffix(path.substring(0, path.length() - 4), suffix); else dst = setFileSuffix(path, suffix); if (file.renameTo(dst)) { dst.setLastModified(System.currentTimeMillis()); LOG.debug("Rename {} to {}", new Object[] { file, dst }); try { writeFailedAuditLogMessage(proxyAEE, dst, null, calledAET, prop); } catch (IOException e) { LOG.error("Failed to write audit log message"); if (LOG.isDebugEnabled()) e.printStackTrace(); } } else { LOG.error("Failed to rename {} to {}", new Object[] { file, dst }); } }
From source file:com.kalix.tools.kibana.KibanaController.java
/** * download kibana from remote server//from w w w . ja v a 2 s.c om * * @throws Exception */ public void download() throws Exception { File target = new File(workingDirectory, KIBANA_FOLDER); if (target.exists()) { LOGGER.warn("Kibana folder already exists, download is skipped"); return; } LOGGER.debug("Downloading Kibana from {}", KIBANA_LOCATION); if (isWindows()) { try (ZipArchiveInputStream inputStream = new ZipArchiveInputStream( new URL(KIBANA_LOCATION).openStream())) { ZipArchiveEntry entry; while ((entry = (ZipArchiveEntry) inputStream.getNextEntry()) != null) { File file = new File(workingDirectory, entry.getName()); if (entry.isDirectory()) { file.mkdirs(); } else { int read; byte[] buffer = new byte[4096]; try (FileOutputStream outputStream = new FileOutputStream(file)) { while ((read = inputStream.read(buffer, 0, 4096)) != -1) { outputStream.write(buffer, 0, read); } } } } } } else { try (GzipCompressorInputStream gzInputStream = new GzipCompressorInputStream( new URL(KIBANA_LOCATION).openStream())) { try (TarArchiveInputStream inputStream = new TarArchiveInputStream(gzInputStream)) { TarArchiveEntry entry; while ((entry = (TarArchiveEntry) inputStream.getNextEntry()) != null) { File file = new File(workingDirectory, entry.getName()); if (entry.isDirectory()) { file.mkdirs(); } else { int read; byte[] buffer = new byte[4096]; try (FileOutputStream outputStream = new FileOutputStream(file)) { while ((read = inputStream.read(buffer, 0, 4096)) != -1) { outputStream.write(buffer, 0, read); } } file.setLastModified(entry.getLastModifiedDate().getTime()); if (entry instanceof TarArchiveEntry) { int mode = ((TarArchiveEntry) entry).getMode(); if ((mode & 00100) > 0) { file.setExecutable(true, (mode & 00001) == 0); } } } } } } } overrideConfig(); }
From source file:de.burlov.amazon.s3.dirsync.DirSync.java
private void syncDown(Folder folder, File baseDir, Collection<LocalFile> files, boolean snapShot) { for (LocalFile item : files) { FileInfo info = folder.getIndexData().get(item.getRelativeName()); File file = item.getLocalFile(); if (info != null) { /*/*from ww w . ja va 2s.c om*/ * Vermissten oder geanderte Datei runterladen */ try { /* * Zuerst Hashwert berechnen und vergleichen. Villeicht ist das Download gar * nicht noetig */ byte[] hash = null; if (file.exists()) { hash = digestFile(file, shaDigest); } if (info.getHash() == null || !Arrays.equals(info.getHash(), hash)) { log.info("Downloading " + item.getRelativeName()); downloadFile(file, getFileKey(info.getStorageId())); transferredFiles++; transferredData += file.length(); } file.setLastModified(info.getLastModified()); } catch (Exception e) { log.error("File download '" + item.getRelativeName() + "' failed. " + e.getLocalizedMessage()); } } else if (snapShot) { /* * neue lokale Dateien in 'snap shot' Modus loeschen */ log.info("Delete " + file.getAbsolutePath()); if (!file.delete()) { log.warn("Unable to delete file: " + file.getAbsolutePath()); } else { deletedFiles++; } /* * Wenn Verzeichnis keine Dateien mehr enthaelt, muss er auch geloescht werden */ deleteEmptyFolder(baseDir, file.getParentFile()); } } }
From source file:org.apache.jackrabbit.core.data.LocalCache.java
/** * Store an item in the cache and return the input stream. If cache is in * purgeMode or file doesn't exists, inputstream from a * {@link TransientFileFactory#createTransientFile(String, String, File)} is * returned. Otherwise inputStream from cached file is returned. This method * doesn't close the incoming inputstream. * /*from ww w . ja va 2s .c o m*/ * @param fileName the key of cache. * @param in {@link InputStream} * @return the (new) input stream. */ public InputStream store(String fileName, final InputStream in) throws IOException { fileName = fileName.replace("\\", "/"); File f = getFile(fileName); long length = 0; synchronized (this) { if (!f.exists() || isInPurgeMode()) { OutputStream out = null; File transFile = null; try { TransientFileFactory tff = TransientFileFactory.getInstance(); transFile = tff.createTransientFile("s3-", "tmp", tmp); out = new BufferedOutputStream(new FileOutputStream(transFile)); length = IOUtils.copyLarge(in, out); } finally { IOUtils.closeQuietly(out); } // rename the file to local fs cache if (canAdmitFile(length) && (f.getParentFile().exists() || f.getParentFile().mkdirs()) && transFile.renameTo(f) && f.exists()) { if (transFile.exists() && transFile.delete()) { LOG.info("tmp file [{}] not deleted successfully", transFile.getAbsolutePath()); } transFile = null; LOG.debug("file [{}] added to local cache.", fileName); cache.put(fileName, f.length()); } else { f = transFile; } } else { // f.exists and not in purge mode f.setLastModified(System.currentTimeMillis()); cache.put(fileName, f.length()); } cache.tryPurge(); return new LazyFileInputStream(f); } }