Java Path File List nio registerRecursive(final WatchService watcher, final List startingPaths)

Here you can find the source of registerRecursive(final WatchService watcher, final List startingPaths)

Description

Register the given directory, and all its sub-directories, with the WatchService.

License

Apache License

Declaration

public static void registerRecursive(final WatchService watcher, final List<Path> startingPaths)
        throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import com.sun.nio.file.SensitivityWatchEventModifier;

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.List;

public class Main {
    /**//from w ww  .j  av a  2  s  .co m
     * Register the given directory, and all its sub-directories, with the WatchService.
     * Populates the given 'keys' map with WatchKeys -> Paths.
     */
    public static void registerRecursive(final WatchService watcher, final List<Path> startingPaths)
            throws IOException {
        for (Path start : startingPaths) {
            // register directory and sub-directories
            Files.walkFileTree(start, new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                    register(watcher, dir);
                    return FileVisitResult.CONTINUE;
                }
            });
        }
    }

    /**
     * Register the given directory with the WatchService
     */
    public static void register(final WatchService watcher, final Path dir) throws IOException {
        dir.register(
                watcher, new WatchEvent.Kind[] { StandardWatchEventKinds.ENTRY_MODIFY,
                        StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE },
                SensitivityWatchEventModifier.HIGH);
    }
}

Related

  1. mergeFiles(List files, Path mergedFile)
  2. mergeInto(List parts, OutputStream out)
  3. pathContainsAny(List strings)
  4. recursiveListFiles(Path file)
  5. recusivelyCollectFileListing(ArrayList rc, Path base, Path directory)
  6. retrieveTokenFilesInDirImportableFrom(Path dir, List excludedTokenFiles)
  7. toCliString(Path agentPath, String param)
  8. toFile(Path file, String list)
  9. uncheckedList(final Path path)