當前位置: 首頁>>代碼示例>>Java>>正文


Java Files.getLastModifiedTime方法代碼示例

本文整理匯總了Java中java.nio.file.Files.getLastModifiedTime方法的典型用法代碼示例。如果您正苦於以下問題:Java Files.getLastModifiedTime方法的具體用法?Java Files.getLastModifiedTime怎麽用?Java Files.getLastModifiedTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.file.Files的用法示例。


在下文中一共展示了Files.getLastModifiedTime方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: walkClientsForServerFile

import java.nio.file.Files; //導入方法依賴的package包/類
private void walkClientsForServerFile(File serverFile) throws IOException {

        if(!Files.exists(serverFile.getAbsolutePath())) {
            return;
        }

        FileTime modifiedTime = Files.getLastModifiedTime(serverFile.getAbsolutePath());

        List<Inspector> inspectors = new ArrayList<>(getServerFileInspectors(serverFile, modifiedTime));

        for (Client client : clients.values()) {
            File clientFile = client.files.get(serverFile.getId());
            if(clientFile != null) {
                inspectors.addAll(getClientFileInspectors(clientFile));
            }
        }
        inspect(serverFile, inspectors);
    }
 
開發者ID:gaganis,項目名稱:odoxSync,代碼行數:19,代碼來源:RegionWalker.java

示例2: SingleFileBucket

import java.nio.file.Files; //導入方法依賴的package包/類
SingleFileBucket(long bucketNumber, long bucketSize, Encryption encryption, File file) {
    this.bucketSize = bucketSize;
    this.bucketNumber = bucketNumber;
    this.encryption = encryption;
    baseOffset = bucketNumber * this.bucketSize;
    upperBound = baseOffset + this.bucketSize - 1;
    LOGGER.debug("starting to monitor bucket {} with file {}", bucketNumber, file.getAbsolutePath());
    this.file = file;
    try {
        filePath = file.toPath();
        final long existingFileSize = Files.size(filePath);
        this.fileWasZero = existingFileSize == 0;
        lastModifiedTime = Files.getLastModifiedTime(filePath);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
 
開發者ID:MineboxOS,項目名稱:minebox,代碼行數:18,代碼來源:SingleFileBucket.java

示例3: postVisitDirectory

import java.nio.file.Files; //導入方法依賴的package包/類
@Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
    // fix up modification time of directory when done
    if (exc == null) {
        Path newdir = target.resolve(source.relativize(dir));
        try {
            FileTime time = Files.getLastModifiedTime(dir);
            Files.setLastModifiedTime(newdir, time);
        } catch (IOException x) {
            System.err.format("Unable to copy all attributes to: %s: %s%n", newdir, x);
        }
        try {
            if (operation == Operation.CUT) {
                Files.delete(dir);
            }
        } catch (IOException e) {
            System.err.format("Unable to delete directory: %s: %s%n", newdir, e);
        }
    }
    return CONTINUE;
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:21,代碼來源:Copy.java

示例4: nextBatchArea

import java.nio.file.Files; //導入方法依賴的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);
}
 
開發者ID:gaganis,項目名稱:odoxSync,代碼行數:27,代碼來源:SlowFileProcessor.java

示例5: test

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Exercise Files.setLastModifiedTime on the given file
 */
void test(Path path) throws Exception {
    FileTime now = Files.getLastModifiedTime(path);
    FileTime zero = FileTime.fromMillis(0L);

    Path result = Files.setLastModifiedTime(path, zero);
    assertTrue(result == path);
    assertEquals(Files.getLastModifiedTime(path), zero);

    result = Files.setLastModifiedTime(path, now);
    assertTrue(result == path);
    assertEquals(Files.getLastModifiedTime(path), now);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:SetLastModifiedTime.java

示例6: getFileTime

import java.nio.file.Files; //導入方法依賴的package包/類
private FileTime getFileTime(File file) {
    try{
        return Files.getLastModifiedTime(file.getAbsolutePath());
    } catch (IOException e) {
        return null;
    }
}
 
開發者ID:gaganis,項目名稱:odoxSync,代碼行數:8,代碼來源:FileModifiedComparator.java

示例7: postVisitDirectory

import java.nio.file.Files; //導入方法依賴的package包/類
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
    // fix up modification time of directory when done
    if (exc == null) {
        Path newdir = target.resolve(source.relativize(dir));            
        try {
            FileTime time = Files.getLastModifiedTime(dir);
            Files.setLastModifiedTime(newdir, time);
        } catch (IOException x) {
            LOGGER.log(Level.WARNING, "Unable to copy all attributes to: " + newdir, x);
        }
    }
    return CONTINUE;
}
 
開發者ID:chipKIT32,項目名稱:chipKIT-importer,代碼行數:15,代碼來源:CopyingFileVisitor.java

示例8: processFileFast

import java.nio.file.Files; //導入方法依賴的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);
    }
}
 
開發者ID:gaganis,項目名稱:odoxSync,代碼行數:42,代碼來源:DirectoryScanner.java

示例9: doBeforeFileRead

import java.nio.file.Files; //導入方法依賴的package包/類
@Override
public void doBeforeFileRead(RandomAccessFile randomAccessFile) throws IOException {
    fileLastModifiedTime = Files.getLastModifiedTime(file.getAbsolutePath());
}
 
開發者ID:gaganis,項目名稱:odoxSync,代碼行數:5,代碼來源:FastFileProcessor.java

示例10: testOneModule

import java.nio.file.Files; //導入方法依賴的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!");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:65,代碼來源:MOptionTest.java

示例11: main

import java.nio.file.Files; //導入方法依賴的package包/類
public static void main(String... args) throws Exception {

        Path root = Paths.get(ClasspathDependencies.class.getSimpleName() + "Test");

        delete(root);

        Path src = root.resolve("src");
        Path classes = root.resolve("classes");
        Path srcDep = root.resolve("srcDep");
        Path classesDep = root.resolve("classesDep");

        ////////////////////////////////////////////////////////////////////////
        headline("Create a test dependency, Dep.class, and put it in the classpath dir");
        String depCode = "package dep; public class Dep { public void m1() {} }";
        toolbox.writeFile(srcDep.resolve("dep/Dep.java"), depCode);
        int rc = compile("-d", classesDep, "--state-dir=" + classesDep, srcDep);
        check(rc == 0, "Compilation failed unexpectedly");

        ////////////////////////////////////////////////////////////////////////
        headline("Compile and link against the Dep.class");
        toolbox.writeFile(src.resolve("pkg/C.java"),
                          "package pkg;" +
                          "import dep.Dep;" +
                          "public class C { Dep dep; public void m() { new Dep().m1(); } }");
        rc = compile("-d", classes, "--state-dir=" + classes, src, "-cp", classesDep);
        check(rc == 0, "Compilation failed unexpectedly");
        FileTime modTime1 = Files.getLastModifiedTime(classes.resolve("pkg/C.class"));

        ////////////////////////////////////////////////////////////////////////
        headline("Update dependency (without changing the public api)");
        Thread.sleep(2000);
        depCode = depCode.replaceAll("}$", "private void m2() {} }");
        toolbox.writeFile(srcDep.resolve("dep/Dep.java"), depCode);
        rc = compile("-d", classesDep, "--state-dir=" + classesDep, srcDep);
        check(rc == 0, "Compilation failed unexpectedly");

        ////////////////////////////////////////////////////////////////////////
        headline("Make sure that this does not trigger recompilation of C.java");
        rc = compile("-d", classes, "--state-dir=" + classes, src, "-cp", classesDep);
        check(rc == 0, "Compilation failed unexpectedly");
        FileTime modTime2 = Files.getLastModifiedTime(classes.resolve("pkg/C.class"));
        check(modTime1.equals(modTime2), "Recompilation erroneously triggered");

        ////////////////////////////////////////////////////////////////////////
        headline("Update public API of dependency");
        Thread.sleep(2000);
        depCode = depCode.replace("m1()", "m1(String... arg)");
        toolbox.writeFile(srcDep.resolve("dep/Dep.java"), depCode);
        rc = compile("-d", classesDep, "--state-dir=" + classesDep, srcDep);
        check(rc == 0, "Compilation failed unexpectedly");

        ////////////////////////////////////////////////////////////////////////
        headline("Make sure that recompilation of C.java is triggered");
        rc = compile("-d", classes, "--state-dir=" + classes, src, "-cp", classesDep);
        check(rc == 0, "Compilation failed unexpectedly");
        FileTime modTime3 = Files.getLastModifiedTime(classes.resolve("pkg/C.class"));
        check(modTime2.compareTo(modTime3) < 0, "Recompilation not triggered");
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:59,代碼來源:ClasspathDependencies.java


注:本文中的java.nio.file.Files.getLastModifiedTime方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。