List of usage examples for java.io File setLastModified
public boolean setLastModified(long time)
From source file:com.liferay.blade.cli.command.InstallExtensionCommandTest.java
@Test public void testInstallCustomExtensionTwiceOverwrite() throws Exception { String jarName = _sampleCommandJarFile.getName(); File extensionJar = new File(_extensionsDir, jarName); String[] args = { "extension", "install", _sampleCommandJarFile.getAbsolutePath() }; Path extensionPath = extensionJar.toPath(); BladeTestResults bladeTestResults = TestUtil.runBlade(_rootDir, _extensionsDir, args); String output = bladeTestResults.getOutput(); _testJarsDiff(_sampleCommandJarFile, extensionJar); Assert.assertTrue("Expected output to contain \"successful\"\n" + output, output.contains(" successful")); Assert.assertTrue(output.contains(jarName)); File tempDir = temporaryFolder.newFolder("overwrite"); Path tempPath = tempDir.toPath(); Path sampleCommandPath = tempPath.resolve(_sampleCommandJarFile.getName()); Files.copy(_sampleCommandJarFile.toPath(), sampleCommandPath, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING); File sampleCommandFile = sampleCommandPath.toFile(); sampleCommandFile.setLastModified(0); args = new String[] { "extension", "install", sampleCommandFile.getAbsolutePath() }; output = _testBladeWithInteractive(_rootDir, _extensionsDir, args, "y"); _testJarsDiff(sampleCommandFile, extensionJar); Assert.assertTrue("Expected output to contain \"Overwrite\"\n" + output, output.contains("Overwrite")); boolean assertCorrect = output.contains(" installed successfully"); if (!assertCorrect) { Assert.assertTrue("Expected output to contain \"installed successfully\"\n" + output, assertCorrect); }//www . ja v a 2 s .c o m File extensionFile = extensionPath.toFile(); Assert.assertEquals(sampleCommandFile.lastModified(), extensionFile.lastModified()); }
From source file:org.dataone.proto.trove.mn.service.v1.impl.MNStorageImpl.java
@Override public Identifier create(Identifier pid, InputStream object, SystemMetadata sysmeta) throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, UnsupportedType, InsufficientResources, InvalidSystemMetadata, NotImplemented, InvalidRequest { try {/*from w w w.j av a2 s . c o m*/ File systemMetadata = new File(dataoneCacheDirectory + File.separator + "meta" + File.separator + EncodingUtilities.encodeUrlPathSegment(pid.getValue())); TypeMarshaller.marshalTypeToFile(sysmeta, systemMetadata.getAbsolutePath()); if (systemMetadata.exists()) { systemMetadata.setLastModified(sysmeta.getDateSysMetadataModified().getTime()); } else { throw new ServiceFailure("1190", "SystemMetadata not found on FileSystem after create"); } File objectFile = new File(dataoneCacheDirectory + File.separator + "object" + File.separator + EncodingUtilities.encodeUrlPathSegment(pid.getValue())); if (!objectFile.exists() && objectFile.createNewFile()) { objectFile.setReadable(true); objectFile.setWritable(true); objectFile.setExecutable(false); } if (object != null) { FileOutputStream objectFileOutputStream = new FileOutputStream(objectFile); BufferedInputStream inputStream = new BufferedInputStream(object); byte[] barray = new byte[SIZE]; int nRead = 0; while ((nRead = inputStream.read(barray, 0, SIZE)) != -1) { objectFileOutputStream.write(barray, 0, nRead); } objectFileOutputStream.flush(); objectFileOutputStream.close(); inputStream.close(); } } catch (FileNotFoundException ex) { throw new ServiceFailure("1190", ex.getCause().toString() + ":" + ex.getMessage()); } catch (IOException ex) { throw new ServiceFailure("1190", ex.getMessage()); } catch (JiBXException ex) { throw new InvalidSystemMetadata("1180", ex.getMessage()); } return pid; }
From source file:com.liferay.blade.cli.command.InstallExtensionCommandTest.java
@Test public void testInstallCustomExtensionTwiceDontOverwrite() throws Exception { String jarName = _sampleCommandJarFile.getName(); File extensionJar = new File(_extensionsDir, jarName); String[] args = { "extension", "install", _sampleCommandJarFile.getAbsolutePath() }; Path extensionPath = extensionJar.toPath(); BladeTestResults bladeTestResults = TestUtil.runBlade(_rootDir, _extensionsDir, args); String output = bladeTestResults.getOutput(); _testJarsDiff(_sampleCommandJarFile, extensionJar); Assert.assertTrue("Expected output to contain \"successful\"\n" + output, output.contains(" successful")); Assert.assertTrue(output.contains(jarName)); File tempDir = temporaryFolder.newFolder("overwrite"); Path tempPath = tempDir.toPath(); Path sampleCommandPath = tempPath.resolve(_sampleCommandJarFile.getName()); Files.copy(_sampleCommandJarFile.toPath(), sampleCommandPath, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING); File sampleCommandFile = sampleCommandPath.toFile(); sampleCommandFile.setLastModified(0); args = new String[] { "extension", "install", sampleCommandFile.getAbsolutePath() }; output = _testBladeWithInteractive(_rootDir, _extensionsDir, args, "n"); Assert.assertTrue("Expected output to contain \"already exists\"\n" + output, output.contains(" already exists")); Assert.assertFalse("Expected output to not contain \"installed successfully\"\n" + output, output.contains(" installed successfully")); Assert.assertTrue(sampleCommandFile.lastModified() == 0); File extensionFile = extensionPath.toFile(); Assert.assertFalse(extensionFile.lastModified() == 0); output = _testBladeWithInteractive(_rootDir, _extensionsDir, args, "defaultShouldBeNo"); Assert.assertFalse(extensionFile.lastModified() == 0); Assert.assertTrue("Expected output to contain \"already exists\"\n" + output, output.contains(" already exists")); Assert.assertFalse("Expected output to not contain \"Overwriting\"\n" + output, output.contains("Overwriting")); Assert.assertFalse("Expected output to not contain \"installed successfully\"\n" + output, output.contains(" installed successfully")); }
From source file:com.dattasmoon.pebble.plugin.FireReceiver.java
public void setNotificationSettings(final Context context, int bundleVersionCode, Mode mode, String packageList) {/* www . j a va 2s . c o m*/ if (Constants.IS_LOGGABLE) { switch (mode) { case OFF: Log.i(Constants.LOG_TAG, "Mode is: off"); break; case INCLUDE: Log.i(Constants.LOG_TAG, "Mode is: include only"); break; case EXCLUDE: Log.i(Constants.LOG_TAG, "Mode is: exclude"); break; default: Log.i(Constants.LOG_TAG, "Mode is: unknown (" + mode + ")"); } Log.i(Constants.LOG_TAG, "Package list is: " + packageList); } Editor editor = context.getSharedPreferences(Constants.LOG_TAG + "_preferences", context.MODE_MULTI_PROCESS | context.MODE_PRIVATE).edit(); editor.putInt(Constants.PREFERENCE_MODE, mode.ordinal()); editor.putBoolean(Constants.PREFERENCE_TASKER_SET, true); editor.putString(Constants.PREFERENCE_PACKAGE_LIST, packageList); if (!editor.commit()) { try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } editor.commit(); } File watchFile = new File(context.getFilesDir() + "PrefsChanged.none"); if (!watchFile.exists()) { try { watchFile.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } watchFile.setLastModified(System.currentTimeMillis()); }
From source file:com.virtualparadigm.packman.processor.JPackageManagerOld.java
public static boolean configureCommons(File tempDir, Configuration configuration) { logger.info("PackageManager::configure()"); boolean status = true; if (tempDir != null && configuration != null && !configuration.isEmpty()) { Map<String, String> substitutionContext = JPackageManagerOld.createSubstitutionContext(configuration); StrSubstitutor strSubstitutor = new StrSubstitutor(substitutionContext); String templateContent = null; long lastModified; Collection<File> patchFiles = FileUtils.listFiles( new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.PATCH_DIR_NAME + "/" + JPackageManagerOld.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(); }// w w w . j a v a 2 s .c o m } } Collection<File> scriptFiles = FileUtils.listFiles( new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.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:nya.miku.wishmaster.cache.FileCache.java
/** * ?/*from w ww. j a v a 2 s .c o m*/ * @param fileName ? * @return , ? ??, null, ? ?? */ public synchronized File get(String fileName) { File file = pathToFile(fileName); if (file.exists() && !file.isDirectory()) { file.setLastModified(System.currentTimeMillis()); database.touch(fileName); return file; } return null; }
From source file:org.goobi.presentation.contentservlet.controller.ContentCache.java
/************************************************************************************* * write file from cache with given id to given {@link OutputStream} * //from www . j av a 2 s .c o m * @param out OutputStream where to write the cached file * @param inId ID as String (no file name, no file extension) * @throws CacheException ************************************************************************************/ public void writeToStream(OutputStream out, String inId, String suffix) throws CacheException { if (!cacheContains(inId, suffix)) { throw new CacheException("File already exists in cache."); } /* * -------------------------------- File exists and can be read? -------------------------------- */ File file = getFileForId(inId, suffix); if (!file.exists() || !file.canRead()) { throw new CacheException( "File with given ID (" + inId + ") can not be read. (" + file.getAbsolutePath() + ")"); } // Update Timestamp to be able to find old cache items file.setLastModified(System.currentTimeMillis()); /* * -------------------------------- write File to OutputStream -------------------------------- */ try { FileInputStream in = new FileInputStream(file); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); } catch (FileNotFoundException e) { throw new CacheException("File " + file.getAbsolutePath() + " does not exist.", e); } catch (IOException e) { throw new CacheException("IO-Error while writing file to stream", e); } }
From source file:org.codehaus.mojo.castor.GenerateMojoTest.java
private File createTimeStampWithTime(long time) throws IOException { File timeStampFolder = new File(TIMESTAMP_DIR); File timeStampFile = getTimeStampFile(); if (!timeStampFolder.exists()) { timeStampFolder.mkdirs();// ww w. j av a 2 s . com } if (!timeStampFile.exists()) { FileUtils.touch(timeStampFile); timeStampFile.setLastModified(time); } return timeStampFile; }
From source file:org.geowebcache.storage.MetastoreRemover.java
private void migrateTileDates(JdbcTemplate template, final FilePathGenerator generator) { String query = "select layers.value as layer, gridsets.value as gridset, " + "tiles.parameters_id, tiles.z, tiles.x, tiles.y, created, formats.value as format \n" + "from tiles join layers on layers.id = tiles.layer_id \n" + "join gridsets on gridsets.id = tiles.gridset_id \n" + "join formats on formats.id = tiles.format_id \n" + "order by layer_id, parameters_id, gridset, z, x, y"; final long total = template.queryForLong("select count(*) from (" + query + ")"); log.info("Migrating " + total + " tile creation dates from the metastore to the file system"); template.query(query, new RowCallbackHandler() { int count = 0; public void processRow(ResultSet rs) throws SQLException { // read the result set String layer = rs.getString(1); String gridset = rs.getString(2); String paramsId = rs.getString(3); long z = rs.getLong(4); long x = rs.getLong(5); long y = rs.getLong(6); long created = rs.getLong(7); String format = rs.getString(8); // create the tile and thus the tile path TileObject tile = TileObject.createCompleteTileObject(layer, new long[] { x, y, z }, gridset, format, null, null); tile.setParametersId(paramsId); try { File file = generator.tilePath(tile, MimeType.createFromFormat(format)); // update the last modified according to the date if (file.exists()) { file.setLastModified(created); }//from w ww .j a v a 2s. com } catch (MimeException e) { log.error("Failed to locate mime type for format '" + format + "', this should never happen!"); } count++; if (count % 10000 == 0 || count >= total) { log.info("Migrated " + count + "/" + total + " tile creation dates from the metastore to the file system"); } } }); }
From source file:org.pitest.PitMojoIT.java
/** * Sets up a test of the reporting mojo simulating multiple runs of mvn * install (as in the case where timestampedReports is set to true). First * calls {@link #prepareSiteTest(String)} then walks all directories starting * at target/pit-reports setting their last modified time to 0 (epoch time). * Finally, the directory specified in the {@code latestDir} parameter has its * last modified time set to {@link System#currentTimeMillis()}. * //from w ww.j a v a2 s . c om * @param testPath * {@link String} see {@link #prepareSiteTest(String)} * @param latestDir * {@link String} containing the subdirectory of target/pit-reports * that should be set as the latest, pass an empty string to indicate * the target/pit-reports directory should be the latest * * @return {@link File} representing the temporary folder that was set up for * this execution of the test * @throws Exception */ private File prepareSiteTest(String testPath, String latestDir) throws Exception { File testDir = prepareSiteTest(testPath); // location where the target directory would be if a mvn clean install was executed File testTargetDir = this.buildFilePath(testDir, "target", "pit-reports"); DirectoriesOnlyWalker walker = new DirectoriesOnlyWalker(); for (File f : walker.locateDirectories(testTargetDir)) { f.setLastModified(0L); } assertThat(buildFilePath(testTargetDir, latestDir).setLastModified(System.currentTimeMillis())).isTrue(); return testDir; }