List of usage examples for java.nio.file.attribute FileTime compareTo
@Override public int compareTo(FileTime other)
From source file:Main.java
public static void main(String[] args) throws Exception { long time = System.currentTimeMillis(); FileTime fileTime = FileTime.fromMillis(time); FileTime fileTime1 = FileTime.from(time, TimeUnit.MILLISECONDS); System.out.println(fileTime.compareTo(fileTime1)); }
From source file:com.linkedin.pinot.core.segment.index.loader.SegmentPreProcessorTest.java
@Test public void testV3CreateInvertedIndices() throws Exception { constructSegment();//from w ww. ja v a 2s .c om // Convert segment format to v3. SegmentV1V2ToV3FormatConverter converter = new SegmentV1V2ToV3FormatConverter(); converter.convert(segmentDirectoryFile); File v3SegmentDirectoryFile = new File(segmentDirectoryFile, V3_SEGMENT_NAME); SegmentMetadataImpl segmentMetadata = new SegmentMetadataImpl(v3SegmentDirectoryFile); String segmentVersion = segmentMetadata.getVersion(); Assert.assertEquals(SegmentVersion.valueOf(segmentVersion), SegmentVersion.v3); File singleFileIndex = new File(v3SegmentDirectoryFile, "columns.psf"); FileTime lastModifiedTime = Files.getLastModifiedTime(singleFileIndex.toPath()); long fileSize = singleFileIndex.length(); // Sleep 2 seconds to prevent the same last modified time when modifying the file. Thread.sleep(2000); // Create inverted index the first time. checkInvertedIndexCreation(v3SegmentDirectoryFile, segmentMetadata, false); long addedLength = 0L; try (SegmentDirectory segmentDirectory = SegmentDirectory.createFromLocalFS(v3SegmentDirectoryFile, segmentMetadata, ReadMode.mmap); SegmentDirectory.Reader reader = segmentDirectory.createReader()) { // 8 bytes overhead is for checking integrity of the segment. try (PinotDataBuffer col1Buffer = reader.getIndexFor(COLUMN1_NAME, ColumnIndexType.INVERTED_INDEX)) { addedLength += col1Buffer.size() + 8; } try (PinotDataBuffer col13Buffer = reader.getIndexFor(COLUMN13_NAME, ColumnIndexType.INVERTED_INDEX)) { addedLength += col13Buffer.size() + 8; } } FileTime newLastModifiedTime = Files.getLastModifiedTime(singleFileIndex.toPath()); Assert.assertTrue(newLastModifiedTime.compareTo(lastModifiedTime) > 0); long newFileSize = singleFileIndex.length(); Assert.assertEquals(fileSize + addedLength, newFileSize); // Sleep 2 seconds to prevent the same last modified time when modifying the file. Thread.sleep(2000); // Create inverted index the second time. checkInvertedIndexCreation(v3SegmentDirectoryFile, segmentMetadata, true); Assert.assertEquals(Files.getLastModifiedTime(singleFileIndex.toPath()), newLastModifiedTime); Assert.assertEquals(singleFileIndex.length(), newFileSize); }
From source file:fr.duminy.jbackup.core.ConfigurationManagerTest.java
@Test public void testSaveBackupConfiguration_updateConfig() throws Exception { BackupConfiguration config = createConfiguration(); Path output = testSaveBackupConfiguration(config); FileTime t0 = Files.getLastModifiedTime(output); sleep(1000);//w ww . j ava 2 s. co m output = testSaveBackupConfiguration(config); FileTime t1 = Files.getLastModifiedTime(output); assertThat(t1.compareTo(t0) >= 0).as("t1 > t0").isTrue(); }
From source file:fr.inria.soctrace.tools.ocelotl.core.caches.DichotomyCache.java
/** * Remove a cache file. The used policy is to suppress the file which has * the oldest accessed time//from www . j a va 2s .co m */ public void removeCacheFile() { // Init with current time FileTime oldestDate = FileTime.from(System.currentTimeMillis(), null); CacheParameters oldestParam = null; for (CacheParameters aCacheParam : cachedDichotomy.keySet()) { try { // Get the last access to the file Path path = cachedDichotomy.get(aCacheParam).toPath(); BasicFileAttributes attrs; attrs = Files.readAttributes(path, BasicFileAttributes.class); FileTime currentTime = attrs.lastAccessTime(); // If the access is older than the current oldest if (currentTime.compareTo(oldestDate) < 0) { oldestDate = currentTime; oldestParam = aCacheParam; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // Delete oldest accessed cache if (!cachedDichotomy.get(oldestParam).delete()) { logger.debug("[DICHOTOMY CACHE]: Deletion of cache file " + cachedDichotomy.get(oldestParam).getName() + " failed."); } cachedDichotomy.remove(oldestParam); }
From source file:fr.inria.soctrace.tools.ocelotl.core.caches.DataCache.java
/** * Remove a cache file. The used policy is to suppress the file which has * the oldest accessed time//from ww w. j a va 2 s. c om */ public void removeCacheFile() { // Init with current time FileTime oldestDate = FileTime.from(System.currentTimeMillis(), null); CacheParameters oldestParam = null; for (CacheParameters aCacheParam : cachedData.keySet()) { try { // Get the last access to the file Path path = cachedData.get(aCacheParam).toPath(); BasicFileAttributes attrs; attrs = Files.readAttributes(path, BasicFileAttributes.class); FileTime currentTime = attrs.lastAccessTime(); // If the access is older than the current oldest if (currentTime.compareTo(oldestDate) < 0) { oldestDate = currentTime; oldestParam = aCacheParam; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // Delete oldest accessed cache if (!cachedData.get(oldestParam).delete()) { logger.debug("DataCache: Deletion of cache file " + cachedData.get(oldestParam).getName() + " failed."); } cachedData.remove(oldestParam); }
From source file:org.digidoc4j.ConfigurationTest.java
@SuppressWarnings("ConstantConditions") @Test/*from w ww .j a v a2 s.c om*/ public void clearTSLCache() throws Exception { Configuration myConfiguration = new Configuration(TEST); File fileCacheDirectory = TslLoader.fileCacheDirectory; if (fileCacheDirectory.exists()) { FileUtils.cleanDirectory(fileCacheDirectory); } TSLCertificateSource tslCertificateSource = myConfiguration.getTSL(); tslCertificateSource.refresh(); waitOneSecond(); File oldCachedFile = fileCacheDirectory.listFiles()[0]; FileTime oldCachedFileDate = (FileTime) Files.getAttribute(oldCachedFile.toPath(), "basic:creationTime"); tslCertificateSource.invalidateCache(); myConfiguration.setTSL(null); tslCertificateSource = myConfiguration.getTSL(); tslCertificateSource.refresh(); File newCachedFile = fileCacheDirectory.listFiles()[0]; FileTime newCachedFileDate = (FileTime) Files.getAttribute(newCachedFile.toPath(), "basic:creationTime"); assertTrue(newCachedFileDate.compareTo(oldCachedFileDate) > 0); }