List of usage examples for java.io File setLastModified
public boolean setLastModified(long time)
From source file:com.frostwire.util.ZipUtils.java
private static void unzipEntries(File folder, ZipInputStream zis, int itemCount, long time, ZipListener listener) throws IOException, FileNotFoundException { ZipEntry ze = null;/*ww w. j a v a 2 s . c o m*/ int item = 0; while ((ze = zis.getNextEntry()) != null) { item++; String fileName = ze.getName(); File newFile = new File(folder, fileName); LOG.debug("unzip: " + newFile.getAbsoluteFile()); if (ze.isDirectory()) { if (!newFile.mkdirs()) { break; } continue; } if (listener != null) { int progress = (item == itemCount) ? 100 : (int) (((double) (item * 100)) / (double) (itemCount)); listener.onUnzipping(fileName, progress); } FileOutputStream fos = new FileOutputStream(newFile); try { int n; byte[] buffer = new byte[1024]; while ((n = zis.read(buffer)) > 0) { fos.write(buffer, 0, n); if (listener != null && listener.isCanceled()) { // not the best way throw new IOException("Uncompress operation cancelled"); } } } finally { fos.close(); zis.closeEntry(); } newFile.setLastModified(time); } }
From source file:org.silverpeas.tools.file.lastmodifieddate.LastModifiedDate.java
private LastModifiedDate execute() throws Exception { long newLastModifiedDate = config.getTranslatedDate().getTime(); for (File currentFile : files) { if (currentFile.isFile()) { currentFile.setLastModified(newLastModifiedDate); } else if (currentFile.isDirectory()) { for (File file : FileUtils.listFilesAndDirs(currentFile, FileFilterUtils.trueFileFilter(), FileFilterUtils.trueFileFilter())) { file.setLastModified(newLastModifiedDate); }/*from ww w. j a va 2 s .c o m*/ } } return this; }
From source file:ru.codeinside.LogFileTest.java
@Test public void test() throws URISyntaxException, IOException { final URL resource = getClass().getClassLoader().getResource("log"); assertNotNull(resource);//from w ww .j a va 2s . c o m final File logs = new File(new File("target"), "logs"); FileUtils.deleteDirectory(logs); FileUtils.copyDirectory(new File("src/test/resources/log"), logs, true); File logPackage1 = new File(logs, "c/7/01807d4f1fbc40fca8e12c3becd82dc7"); assertTrue(logPackage1.setLastModified(100000000L)); File logPackage2 = new File(logs, "1/3/fb255dab0152428b92443dcf02051813"); assertTrue(logPackage2.setLastModified(100000011L)); final List<SmevLog> items = new ArrayList<SmevLog>(); LogConverter.Storage storage = new LogConverter.Storage() { @Override public String getLazyDirPath() { return logs.getPath(); } @Override public SmevLog findLogEntry(String marker) { return null; } @Override public void store(SmevLog smevLog) { items.add(smevLog); } }; LogConverter converter = new LogConverter(); converter.setStorage(storage); assertTrue(converter.logToBd()); assertEquals(1, items.size()); SmevLog _1 = items.get(0); assertEquals("fb255dab0152428b92443dcf02051813", _1.getMarker()); assertNotNull(_1.getSendHttp()); assertNotNull(_1.getReceiveHttp()); assertEquals("FSSR01001", _1.getSendPacket().getRecipient()); assertEquals("9330c70a-8b74-4496-9229-7169a9700313", _1.getReceivePacket().getRequestIdRef()); assertTrue(converter.logToBd()); assertEquals(2, items.size()); SmevLog _2 = items.get(1); assertEquals("01807d4f1fbc40fca8e12c3becd82dc7", _2.getMarker()); assertNotNull(_2.getLogDate()); assertNotNull(_2.getSendHttp()); assertNotNull(_2.getReceiveHttp()); assertEquals("9330c70a-8b74-4496-9229-7169a9700313", _2.getSendPacket().getOriginRequestIdRef()); assertEquals("d1a97f4d-9f29-404a-bd86-3f443ec05bb0", _2.getReceivePacket().getRequestIdRef()); assertFalse(converter.logToBd()); assertEquals(2, items.size()); }
From source file:org.springframework.boot.devtools.restart.server.RestartServer.java
private void updateTimeStamp(URL url) { try {/*from w w w .j a v a2 s . co m*/ URL actualUrl = ResourceUtils.extractJarFileURL(url); File file = ResourceUtils.getFile(actualUrl, "Jar URL"); file.setLastModified(System.currentTimeMillis()); } catch (Exception ex) { // Ignore } }
From source file:org.apache.samza.monitor.TestLocalStoreMonitor.java
@Test public void shouldDeleteLocalStoreWhenLastModifiedTimeOfOffsetFileIsGreaterThanOffsetTTL() throws Exception { File offsetFile = createOffsetFile(taskStoreDir); offsetFile.setLastModified(0); localStoreMonitor.monitor();//from ww w .ja va 2 s. c om assertTrue("Offset file should not exist.", !offsetFile.exists()); assertEquals(0, localStoreMonitorMetrics.diskSpaceFreedInBytes.getCount()); }
From source file:org.apache.archiva.consumers.core.repository.DaysOldRepositoryPurgeTest.java
private void setLastModified(String dirPath, long lastModified) { File dir = new File(dirPath); File[] contents = dir.listFiles(); for (File content : contents) { content.setLastModified(lastModified); }/* www.j a va2 s.c o m*/ }
From source file:org.fcrepo.federation.bagit.ManifestMonitorIT.java
@Test public void testEventsReceived() throws Exception { // Now create a listener implementation that will be called for our bag // created event.. CountDownLatch addlatch = new CountDownLatch(1); EventLogger addlogger = getEventLogger(addlatch, Event.NODE_ADDED); CountDownLatch updateLatch = new CountDownLatch(1); EventLogger updateLogger = getEventLogger(updateLatch, Event.PROPERTY_CHANGED); CountDownLatch dellatch = new CountDownLatch(1); EventLogger dellogger = getEventLogger(dellatch, Event.NODE_REMOVED); // create a random bag and move it into the federated directory final long fileSize = 1024L; makeRandomBags(srcDir, 1, 1, fileSize); final File srcBag = new File(srcDir, "randomBag0"); srcBag.renameTo(dstBag);//from w ww .jav a2 s.c o m addlatch.await(15, TimeUnit.SECONDS); verify(addlogger, times(1)).log(Mockito.eq(Event.NODE_ADDED), Mockito.eq("/objects/randomBag0")); // test bag update event final File bagInfo = new File(dstBag, "manifest-md5.txt"); bagInfo.setLastModified(System.currentTimeMillis()); updateLatch.await(15, TimeUnit.SECONDS); verify(updateLogger, times(1)).log(Mockito.eq(Event.PROPERTY_CHANGED), Mockito.startsWith("/objects/randomBag0")); // Test bag remove event FileUtils.deleteDirectory(dstBag); logger.debug("deleted directory: " + dstBag.getAbsolutePath()); dellatch.await(15, TimeUnit.SECONDS); verify(dellogger, Mockito.atLeastOnce()).log(Mockito.eq(Event.NODE_REMOVED), Mockito.eq("/objects/randomBag0")); }
From source file:org.mycore.wcms2.MCRWebPagesSynchronizer.java
private static void copyFile(File srcFile, File destFile, long chunkSize) throws IOException { try (FileInputStream is = new FileInputStream(srcFile); FileOutputStream os = new FileOutputStream(destFile, false)) { FileChannel iChannel = is.getChannel(); FileChannel oChannel = os.getChannel(); long doneBytes = 0L; long todoBytes = srcFile.length(); while (todoBytes != 0L) { long iterationBytes = Math.min(todoBytes, chunkSize); long transferredLength = oChannel.transferFrom(iChannel, doneBytes, iterationBytes); if (iterationBytes != transferredLength) { throw new IOException("Error during file transfer: expected " + iterationBytes + " bytes, only " + transferredLength + " bytes copied."); }//w w w. j a v a 2 s .co m doneBytes += transferredLength; todoBytes -= transferredLength; } } boolean successTimestampOp = destFile.setLastModified(srcFile.lastModified()); if (!successTimestampOp) { LOGGER.warn(String.format(Locale.ROOT, "Could not change timestamp for %s. Index synchronization may be slow.", destFile)); } }
From source file:com.google.dart.tools.update.core.internal.UpdateUtils.java
/** * Unzip a zip file, notifying the given monitor along the way. *//* w ww . j a v a 2 s.c o m*/ public static void unzip(File zipFile, File destination, String taskName, IProgressMonitor monitor) throws IOException { ZipFile zip = new ZipFile(zipFile); //TODO (pquitslund): add real progress units if (monitor != null) { monitor.beginTask(taskName, 1); } Enumeration<ZipArchiveEntry> e = zip.getEntries(); while (e.hasMoreElements()) { ZipArchiveEntry entry = e.nextElement(); File file = new File(destination, entry.getName()); if (entry.isDirectory()) { file.mkdirs(); } else { InputStream is = zip.getInputStream(entry); File parent = file.getParentFile(); if (parent != null && parent.exists() == false) { parent.mkdirs(); } FileOutputStream os = new FileOutputStream(file); try { IOUtils.copy(is, os); } finally { os.close(); is.close(); } file.setLastModified(entry.getTime()); int mode = entry.getUnixMode(); if ((mode & EXEC_MASK) != 0) { file.setExecutable(true); } } } //TODO (pquitslund): fix progress units if (monitor != null) { monitor.worked(1); monitor.done(); } }
From source file:org.pieShare.pieShareApp.service.fileService.FileServiceBase.java
@Override public void setCorrectModificationDate(PieFile file) { PieLogger.trace(this.getClass(), "Date modified {} of {}", file.getLastModified(), file.getRelativeFilePath()); File targetFile = this.getAbsolutePath(file).toFile(); this.fileWatcherService.addPieFileToModifiedList(file); if (!targetFile.setLastModified(file.getLastModified())) { this.fileWatcherService.removePieFileFromModifiedList(file); PieLogger.warn(this.getClass(), "Could not set LastModificationDate: {}", file.getRelativeFilePath()); }//from w w w .jav a 2s.c om }