List of usage examples for java.io File setLastModified
public boolean setLastModified(long time)
From source file:org.ado.minesync.commons.ZipArchiver.java
public void unpackZip(File zipFile, File outputDir) throws IOException { ALog.d(TAG, "unzip file [" + zipFile.getName() + "] to [" + outputDir.getAbsolutePath() + "]"); this.unpackZip(new FileInputStream(zipFile), outputDir); if (!zipFile.setLastModified(outputDir.lastModified())) { Log.w(TAG, "Unable to change modification date to cached zip file [" + zipFile.getName() + "]."); }/*from w w w .j av a2 s. c o m*/ }
From source file:net.sourceforge.kalimbaradio.androidapp.service.DownloadFile.java
private void updateModificationDate(File file) { if (file.exists()) { boolean ok = file.setLastModified(System.currentTimeMillis()); if (!ok) { LOG.warn("Failed to set last-modified date on " + file); }/*from www . j a v a 2s . co m*/ } }
From source file:io.treefarm.plugins.haxe.utils.HaxelibHelper.java
public static int injectPomHaxelib(String artifactId, String artifactVersion, String artifactType, File artifactFile, Logger logger) { //File unpackDirectory = getHaxelibDirectoryForArtifactAndInitialize(artifactId, artifactVersion, logger); File unpackDir = getLibUnpackPath(artifactId, artifactVersion); if (!unpackDir.exists() || artifactFile.lastModified() > unpackDir.lastModified()) { File libDir = getHaxelibDirectoryForArtifactAndInitialize(artifactId, artifactVersion, logger); if (unpackDir.exists()) { FileUtils.deleteQuietly(unpackDir); }/*from ww w. j ava 2 s. c om*/ if (libDir.exists()) { FileUtils.deleteQuietly(libDir); } UnpackHelper unpackHelper = new UnpackHelper() { }; DefaultUnpackMethods unpackMethods = new DefaultUnpackMethods(logger); try { unpackHelper.unpack(unpackDir, artifactType, artifactFile, unpackMethods, null); } catch (Exception e) { logger.error(String.format("Can't unpack %s: %s", artifactId, e)); } for (String fileName : unpackDir.list()) { if (artifactType.equals("jar")) { fileName = getUniqueLibPath(artifactId, artifactVersion); } File firstFile = new File(unpackDir, fileName); firstFile.renameTo(libDir); break; } unpackDir.setLastModified(artifactFile.lastModified()); } int returnValue = 0; // set to specified version returnValue = setVersionFor(artifactId, artifactVersion, logger); return returnValue; }
From source file:org.apache.kylin.common.persistence.FileResourceStore.java
@Override synchronized protected void putResourceImpl(String resPath, InputStream content, long ts) throws IOException { File f = file(resPath); f.getParentFile().mkdirs();/* w w w . j a v a2 s . c om*/ FileOutputStream out = new FileOutputStream(f); try { IOUtils.copy(content, out); } finally { IOUtils.closeQuietly(out); } f.setLastModified(ts); }
From source file:com.virtualparadigm.packman.processor.JPackageManager.java
public static boolean configure(File tempDir, File localConfigurationFile) { logger.info("PackageManager::configure()"); boolean status = true; if (tempDir != null && localConfigurationFile != null) { Configuration configuration = null; try {//from ww w . j a v a 2 s. com configuration = new PropertiesConfiguration(localConfigurationFile); } catch (ConfigurationException ce) { //dont want to error out completely if config file is not loaded ce.printStackTrace(); } if (configuration != null && !configuration.isEmpty()) { Map<String, String> substitutionContext = JPackageManager.createSubstitutionContext(configuration); StrSubstitutor strSubstitutor = new StrSubstitutor(substitutionContext); String templateContent = null; long lastModified; Collection<File> patchFiles = FileUtils.listFiles( new File(tempDir.getAbsolutePath() + "/" + JPackageManager.PATCH_DIR_NAME + "/" + JPackageManager.PATCH_FILES_DIR_NAME), TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY); if (patchFiles != null) { for (File pfile : patchFiles) { logger.debug(" processing patch fileset file: " + pfile.getAbsolutePath()); try { lastModified = pfile.lastModified(); templateContent = FileUtils.readFileToString(pfile); templateContent = strSubstitutor.replace(templateContent); FileUtils.writeStringToFile(pfile, templateContent); pfile.setLastModified(lastModified); } catch (Exception e) { e.printStackTrace(); } } } Collection<File> scriptFiles = FileUtils.listFiles( new File(tempDir.getAbsolutePath() + "/" + JPackageManager.AUTORUN_DIR_NAME), TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY); if (scriptFiles != null) { for (File scriptfile : scriptFiles) { logger.debug(" processing script file: " + scriptfile.getAbsolutePath()); try { lastModified = scriptfile.lastModified(); templateContent = FileUtils.readFileToString(scriptfile); templateContent = strSubstitutor.replace(templateContent); FileUtils.writeStringToFile(scriptfile, templateContent); scriptfile.setLastModified(lastModified); } catch (Exception e) { e.printStackTrace(); } } } } } return status; }
From source file:org.dcm4chee.proxy.dimse.StgCmt.java
static public void copyFile(final Association asAccepted, final File file, File destDir, File dest) throws IOException { FileInputStream fileIN = new FileInputStream(file); FileOutputStream destOut = new FileOutputStream(dest); File infoFile = new File(file.getParent(), file.getName().substring(0, file.getName().indexOf('.')) + ".info"); File infoFileDest = new File(destDir, infoFile.getName()); FileInputStream infoFileIN = new FileInputStream(infoFile); FileOutputStream infoFileDestOut = new FileOutputStream(infoFileDest); try {/*from w ww .j av a2 s . co m*/ if (IOUtils.copy(fileIN, destOut) > 0 || IOUtils.copy(fileIN, destOut) == -1) { dest.setLastModified(System.currentTimeMillis()); LOG.debug("{}: Copy {} to {}", new Object[] { asAccepted, file.getPath(), dest.getPath() }); if (IOUtils.copy(infoFileIN, infoFileDestOut) > 0 || IOUtils.copy(infoFileIN, infoFileDestOut) == -1) { LOG.debug("{}: Copy {} to {}", new Object[] { asAccepted, infoFile.getPath(), infoFileDest.getPath() }); } else LOG.error("{}: failed to Copy {} to {}", new Object[] { asAccepted, infoFile.getPath(), infoFileDest.getPath() }); } else LOG.error("{}: failed to Copy {} to {}", new Object[] { asAccepted, file.getPath(), dest.getPath() }); } finally { fileIN.close(); infoFileIN.close(); destOut.close(); infoFileDestOut.close(); } }
From source file:org.xmlactions.common.io.ResourceUtils.java
/** * Rename a file to a new file name and path * /* w ww . j a va2s . c o m*/ * @param fileNameAndPath * is the existing file * @param newFileNameAndPath * is what we rename it to * @param overWrite * if set true will overwrite an existing file, false wont. * @return true if successfull or false if not */ public static boolean renameFile(String fileNameAndPath, String newFileNameAndPath, boolean overWrite) { File file = new File(fileNameAndPath); if (file.exists() == false) { return (false); // source file does not exist } File newFile = new File(newFileNameAndPath); if (overWrite == false && newFile.exists() == true) { return (false); // unable to overwrite existing file } if (newFile.exists()) { if (newFile.delete() == false) { return (false); // Can't delete file } } if (file.renameTo(newFile) == false) { // Copy file try { copyFile(file, newFile); if (file.delete() == false) { return (false); // can't delete it } } catch (Exception ex) { return (false); // not copied } } if (newFile.setLastModified(file.lastModified()) == false) { return (false); } return (true); // whew }
From source file:org.n52.io.PreRenderingJob.java
private FileOutputStream createFile(String timeseriesId, String interval, String postfix) throws IOException { String chartQualifier = postfix != null ? interval + "_" + postfix : interval; File file = createFileName(timeseriesId, chartQualifier); if (file.exists()) { file.setLastModified(new Date().getTime()); } else {/* ww w . j av a 2s .com*/ file.createNewFile(); } return new FileOutputStream(file); }
From source file:org.openengsb.connector.maven.internal.MavenServiceTest.java
@Test public void build_shouldAssertLogLimit() throws Exception { final Object syncFinish = new Object(); int max = mavenService.getLogLimit(); for (int i = 1; i <= max; i++) { String fileName = "dummyFile" + i; File dummyFile = new File("log", fileName); dummyFile.createNewFile();/*from w w w.j ava 2 s . c om*/ int tresh = 1000 * i; dummyFile.setLastModified(System.currentTimeMillis() - tresh); } mavenService.setUseLogFile(true); mavenService.setSynchronous(false); mavenService.setProjectPath(getPath("test-unit-success")); mavenService.setCommand("clean compile"); mavenService.build(); makeNotifyAnswerForBuildSuccess(syncFinish); Thread waitForBuildEnd = startWaiterThread(syncFinish); waitForBuildEnd.join(); Collection<File> listFiles = FileUtils.listFiles(new File("log"), FileFilterUtils.fileFileFilter(), null); assertThat(listFiles.size(), is(max)); assertThat(listFiles.contains(new File("dummyFile" + max)), is(false)); }
From source file:com.liferay.portal.deploy.hot.ExtHotDeployListener.java
protected void mergeWebXml(String portalWebDir, String pluginWebDir) { if (!FileUtil.exists(pluginWebDir + "WEB-INF/ext-web/docroot/WEB-INF/web.xml")) { return;/*from w w w . j a v a 2 s . c o m*/ } String tmpDir = SystemProperties.get(SystemProperties.TMP_DIR) + StringPool.SLASH + Time.getTimestamp(); WebXMLBuilder.main(new String[] { portalWebDir + "WEB-INF/web.xml", pluginWebDir + "WEB-INF/ext-web/docroot/WEB-INF/web.xml", tmpDir + "/web.xml" }); File portalWebXml = new File(portalWebDir + "WEB-INF/web.xml"); File tmpWebXml = new File(tmpDir + "/web.xml"); tmpWebXml.setLastModified(portalWebXml.lastModified()); CopyTask.copyFile(tmpWebXml, new File(portalWebDir + "WEB-INF"), true, true); FileUtil.deltree(tmpDir); }