Java Code Examples for java.nio.file.Files.getLastModifiedTime()

The following are Jave code examples for showing how to use getLastModifiedTime() of the java.nio.file.Files class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: odoxSync   File: RegionWalker.java   View Source Code Vote up 7 votes
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);
    }
 
Example 2
Project: minebox   File: SingleFileBucket.java   View Source Code Vote up 6 votes
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);
    }
}
 
Example 3
Project: marathonv5   File: Copy.java   View Source Code Vote up 6 votes
@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;
}
 
Example 4
Project: odoxSync   File: SlowFileProcessor.java   View Source Code Vote up 6 votes
@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);
}
 
Example 5
Project: openjdk-jdk10   File: SetLastModifiedTime.java   View Source Code Vote up 6 votes
/**
 * 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);
}
 
Example 6
Project: tools   File: SingleFileBucket.java   View Source Code Vote up 6 votes
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);
    }
}
 
Example 7
Project: odoxSync   File: FileModifiedComparator.java   View Source Code Vote up 5 votes
private FileTime getFileTime(File file) {
    try{
        return Files.getLastModifiedTime(file.getAbsolutePath());
    } catch (IOException e) {
        return null;
    }
}
 
Example 8
Project: chipKIT-importer   File: CopyingFileVisitor.java   View Source Code Vote up 5 votes
@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;
}
 
Example 9
Project: odoxSync   File: DirectoryScanner.java   View Source Code Vote up 4 votes
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);
    }
}
 
Example 10
Project: odoxSync   File: FastFileProcessor.java   View Source Code Vote up 4 votes
@Override
public void doBeforeFileRead(RandomAccessFile randomAccessFile) throws IOException {
    fileLastModifiedTime = Files.getLastModifiedTime(file.getAbsolutePath());
}
 
Example 11
Project: openjdk-jdk10   File: MOptionTest.java   View Source Code Vote up 4 votes
@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!");
    }
}
 
Example 12
Project: openjdk-jdk10   File: ClasspathDependencies.java   View Source Code Vote up 4 votes
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");
    }