本文整理汇总了Java中java.nio.file.attribute.FileTime.compareTo方法的典型用法代码示例。如果您正苦于以下问题:Java FileTime.compareTo方法的具体用法?Java FileTime.compareTo怎么用?Java FileTime.compareTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.attribute.FileTime
的用法示例。
在下文中一共展示了FileTime.compareTo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compare
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
public int compare(File file1, File file2) {
FileTime time1 = getFileTime(file1);
FileTime time2 = getFileTime(file2);
if(time1 == null && time2 == null) {
return 0;
}
if(time1 == null) {
return -1;
}
if(time2 == null) {
return 1;
}
return time1.compareTo(time2);
}
示例2: nextBatchArea
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
@Override
public BatchArea nextBatchArea() throws IOException {
currentBatchRegions.clear();
batchLastModifiedTime = Files.getLastModifiedTime(file.getAbsolutePath());
Long firstRegionOffset = regionsToProcess.remove();
long size = regions.get(firstRegionOffset).getSize();
currentBatchRegions.add(firstRegionOffset);
boolean isSkip = true;
for (int i = 1; i < BATCH_SIZE && !regionsToProcess.isEmpty(); i++) {
Long regionOffset = regionsToProcess.remove();
Region region = regions.get(regionOffset);
size += region.getSize();
FileTime regionSlowModifiedTime = region
.getSlowModifiedTime();
if(regionSlowModifiedTime == null
|| regionSlowModifiedTime.compareTo(batchLastModifiedTime) == -1) {
isSkip = false;
}
currentBatchRegions.add(regionOffset);
}
return new BatchArea(firstRegionOffset, size, currentBatchRegions, isSkip);
}
示例3: getLayerFile
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
/**
* Finds the file that stores the content BLOB for an application layer.
*
* @param layerType the type of layer
* @param sourceFiles the source files the layer must be built from
* @return the newest cached layer file that matches the {@code layerType} and {@code sourceFiles}
*/
public Path getLayerFile(CachedLayerType layerType, Set<Path> sourceFiles)
throws CacheMetadataCorruptedException {
switch (layerType) {
case DEPENDENCIES:
case RESOURCES:
case CLASSES:
CacheMetadata cacheMetadata = cache.getMetadata();
ImageLayers<CachedLayerWithMetadata> cachedLayers =
cacheMetadata.filterLayers().byType(layerType).bySourceFiles(sourceFiles).filter();
// Finds the newest cached layer for the layer type.
FileTime newestLastModifiedTime = FileTime.from(Instant.MIN);
Path newestLayerFile = null;
for (CachedLayerWithMetadata cachedLayer : cachedLayers) {
FileTime cachedLayerLastModifiedTime = cachedLayer.getMetadata().getLastModifiedTime();
if (cachedLayerLastModifiedTime.compareTo(newestLastModifiedTime) > 0) {
newestLastModifiedTime = cachedLayerLastModifiedTime;
newestLayerFile = cachedLayer.getContentFile();
}
}
return newestLayerFile;
default:
throw new UnsupportedOperationException("Can only find layer files for application layers");
}
}
示例4: areSourceFilesModified
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
/**
* Checks all cached layers built from the source files to see if the source files have been
* modified since the newest layer build.
*
* @param sourceFiles the source files to check
* @return true if no cached layer exists that are up-to-date with the source files; false
* otherwise.
*/
public boolean areSourceFilesModified(Set<Path> sourceFiles)
throws IOException, CacheMetadataCorruptedException {
// Grabs all the layers that have matching source files.
ImageLayers<CachedLayerWithMetadata> cachedLayersWithSourceFiles =
cache.getMetadata().filterLayers().bySourceFiles(sourceFiles).filter();
if (cachedLayersWithSourceFiles.isEmpty()) {
return true;
}
FileTime sourceFilesLastModifiedTime = FileTime.from(Instant.MIN);
for (Path path : sourceFiles) {
FileTime lastModifiedTime = getLastModifiedTime(path);
if (lastModifiedTime.compareTo(sourceFilesLastModifiedTime) > 0) {
sourceFilesLastModifiedTime = lastModifiedTime;
}
}
// Checks if at least one of the matched layers is up-to-date.
for (CachedLayerWithMetadata cachedLayer : cachedLayersWithSourceFiles) {
if (sourceFilesLastModifiedTime.compareTo(cachedLayer.getMetadata().getLastModifiedTime())
<= 0) {
// This layer is an up-to-date layer.
return false;
}
}
return true;
}
示例5: getSample
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
public BatchArea getSample(LinkedList<Long> currentBatchRegions, Long regionOffset, Region region) {
long sampleSize = region.getSize() <= SAMPLE_SIZE ? region.getSize() : SAMPLE_SIZE;
long offset = regionOffset + region.getSize() - sampleSize;
currentBatchRegions.add(regionOffset);
FileTime regionFastModifiedTime = region
.getFastModifiedTime();
boolean isSkip = regionFastModifiedTime != null
&& regionFastModifiedTime.compareTo(fileLastModifiedTime) >= 0;
return new BatchArea(offset, sampleSize, currentBatchRegions, isSkip);
}
示例6: processFileFast
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
private void processFileFast(File file) {
try {
boolean doScan = false;
Path path = Paths.get(workingDirectory, file.getName());
if(!Files.exists(path)) {
return;
}
FileTime lastModifiedTime = Files.getLastModifiedTime(path);
if (lastModifiedTime.compareTo(file.getLastModified()) == 0) {
logger.fine(" File has not been modified [" + file.getName() + "]");
} else {
doScan = true;
}
file.setLastModified(lastModifiedTime);
long size = Files.size(path);
if (size != file.getSize()) {
logger.fine("Recalculation regions for [" + file.getName() + "]");
reCalculateRegions(file);
doScan = true;
}
if (doScan) {
long startTime = System.currentTimeMillis();
logger.fine("Starting scan for [" + file.getName() + "]");
FileScanner fileScanner = new FileScanner(workingDirectory,
new FastFileProcessorFactory(new FileRegionHashMapDigestHandler()), activityStaler, false);
fileScanner.scanFile(file);
long duration = System.currentTimeMillis() - startTime;
logger.fine("Finished scan for [" + file.getName() + "] in [" + duration + "ms]");
}
} catch (IOException e) {
logger.log(Level.SEVERE, "Unable to scan file [" + file.getName() + "]", e);
}
}
示例7: testOneModule
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
@Test
public void testOneModule(Path base) throws Exception {
Path src = base.resolve("src");
Path m1 = src.resolve("m1x");
Path build = base.resolve("build");
Files.createDirectories(build);
tb.writeJavaFiles(m1,
"module m1x {}",
"package test; public class Test {}");
new JavacTask(tb)
.options("-m", "m1x", "--module-source-path", src.toString(), "-d", build.toString())
.run(Task.Expect.SUCCESS)
.writeAll();
Path moduleInfoClass = build.resolve("m1x/module-info.class");
Path testTestClass = build.resolve("m1x/test/Test.class");
FileTime moduleInfoTimeStamp = Files.getLastModifiedTime(moduleInfoClass);
FileTime testTestTimeStamp = Files.getLastModifiedTime(testTestClass);
Path moduleInfo = m1.resolve("module-info.java");
if (moduleInfoTimeStamp.compareTo(Files.getLastModifiedTime(moduleInfo)) < 0) {
throw new AssertionError("Classfiles too old!");
}
Path testTest = m1.resolve("test/Test.java");
if (testTestTimeStamp.compareTo(Files.getLastModifiedTime(testTest)) < 0) {
throw new AssertionError("Classfiles too old!");
}
Thread.sleep(2000); //timestamps
new JavacTask(tb)
.options("-m", "m1x", "--module-source-path", src.toString(), "-d", build.toString())
.run(Task.Expect.SUCCESS)
.writeAll();
if (!moduleInfoTimeStamp.equals(Files.getLastModifiedTime(moduleInfoClass))) {
throw new AssertionError("Classfile update!");
}
if (!testTestTimeStamp.equals(Files.getLastModifiedTime(testTestClass))) {
throw new AssertionError("Classfile update!");
}
Thread.sleep(2000); //timestamps
Files.setLastModifiedTime(testTest, FileTime.fromMillis(System.currentTimeMillis()));
new JavacTask(tb)
.options("-m", "m1x", "--module-source-path", src.toString(), "-d", build.toString())
.run(Task.Expect.SUCCESS)
.writeAll();
if (!moduleInfoTimeStamp.equals(Files.getLastModifiedTime(moduleInfoClass))) {
throw new AssertionError("Classfile update!");
}
if (Files.getLastModifiedTime(testTestClass).compareTo(Files.getLastModifiedTime(testTest)) < 0) {
throw new AssertionError("Classfiles too old!");
}
}