Package java.nio.file

Examples of java.nio.file.WatchService


  @SuppressWarnings({ "rawtypes", "unchecked" })
  public static void watchPlayListDirectory(final JList<?> displayList) {

    try {
      final WatchService watcher = FileSystems.getDefault()
          .newWatchService();
      final Path dir = Paths.get(Constants.DATA_PATH + "playlist/");
      dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);

      System.out.println("Watch Service registered for dir: "
          + dir.getFileName());

      while (true) {
        WatchKey key;
        try {
          key = watcher.take();
        } catch (final InterruptedException ex) {
          return;
        }

        for (final WatchEvent<?> event : key.pollEvents()) {
View Full Code Here


   * @throws IOException
   * @throws InterruptedException
   */
  public static void main(String[] args) throws IOException, InterruptedException {
    Path rootDir = Paths.get("new","directory2");
    WatchService watchService = FileSystems.getDefault().newWatchService();
    rootDir.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY);

    WatchKey watchKey;
    while (true) {
      watchKey = watchService.take();
      processEvenKey(watchKey);
      watchKey.reset();
    }
  }
View Full Code Here

            this.modulePath = modulePath;
        }

        public void run() {
            try {
                WatchService watcher = FileSystems.getDefault().newWatchService();
                Path path = FileSystems.getDefault().getPath(this.modulePath);
                WatchKey key = path.getParent().register(watcher, ENTRY_MODIFY);

                for (;;) {
                    key = watcher.take();
                    for (WatchEvent event: key.pollEvents()) {
                        if (event.kind() == ENTRY_MODIFY){
                            WatchEvent<Path> ev = (WatchEvent<Path>)event;
                            Path filename = ev.context();
                            if (filename.equals(path.getFileName())){
View Full Code Here

        task.updateMessage("watching...");
        task.updateDetailMessage(TASK_DETAIL_PATH, path);

        try {
          Path root = Paths.get(path);
          WatchService watcher = root.getFileSystem().newWatchService();
          register(root, watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE);
          while (true) {
            final WatchKey key = watcher.take();
            for (WatchEvent<?> event : key.pollEvents()) {
             
              @SuppressWarnings("unchecked")
              Path item = ((WatchEvent<Path>) event).context();
              Path dir = keys.get(key);
View Full Code Here

//    String dirOut = "/Users/lucas/Downloads/ilegra/out";
   
    String dirIn = "C:\\data\\in";
    String dirOut = "C:\\dados\\out";

    WatchService watcher = FileSystems.getDefault().newWatchService();

    Path dir = Paths.get(dirIn);
    try {
      dir.register(watcher, StandardWatchEventKinds.ENTRY_CREATE);
    } catch (IOException x) {
      System.err.println(x);
    }

    for (;;) {

      WatchKey key;
      try {
        key = watcher.take();
      } catch (InterruptedException x) {
        return;
      }

      for (WatchEvent<?> event : key.pollEvents()) {
View Full Code Here

@Mojo(name = "watch")
public class WatchMojo extends SofiaMojo {
  @Override
  public void execute() throws MojoExecutionException {
    try {
      WatchService watcher = FileSystems.getDefault().newWatchService();
      Path inputPath = getInputFile().toPath();
      Path dir = inputPath.getParent();
      dir.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY);
      getLog().info("Watching " + inputPath + " for changes");
      generate();
      boolean valid = true;
      while (valid) {
        WatchKey key = watcher.take();
        for (WatchEvent<?> event : key.pollEvents()) {
          if (event.kind() == StandardWatchEventKinds.OVERFLOW) {
            continue;
          }
          WatchEvent<Path> ev = (WatchEvent<Path>) event;
View Full Code Here

        }
        // otherwise use the default extra properties storage

        if (enableEvents) {
            try {
                WatchService watchService = FileSystems.getDefault().newWatchService();
                monitoringTask = Executors.newSingleThreadExecutor(new NamedThreadFactory("modeshape-fs-connector-monitor"))
                                          .submit(new MonitoringTask(watchService, this, Paths.get(directoryAbsolutePath)));
            } catch (UnsupportedOperationException e) {
                log().warn("Unable to to turn on monitoring, because it is not supported on this OS");
            }
View Full Code Here

  @Test
  public void testPathMethodsThrow() throws IOException {
    Path p = fs.getPath("/foo");
    Files.createDirectory(p);

    WatchService ws = fs.newWatchService();

    fs.close();

    try {
      p.register(ws, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
View Full Code Here

    }
  }

  @Test
  public void testOpenWatchServicesClosed() throws IOException {
    WatchService ws1 = fs.newWatchService();
    WatchService ws2 = fs.newWatchService();

    assertNull(ws1.poll());
    assertNull(ws2.poll());

    fs.close();

    try {
      ws1.poll();
      fail();
    } catch (ClosedWatchServiceException expected) {
    }

    try {
      ws2.poll();
      fail();
    } catch (ClosedWatchServiceException expected) {
    }
  }
View Full Code Here

  private static boolean shutdown = false;

  public static void main(String[] args) {

    try {
      WatchService watcher = FileSystems.getDefault().newWatchService();

      Path dir = FileSystems.getDefault().getPath("/usr/karianna");

      WatchKey key = dir.register(watcher, ENTRY_MODIFY);

      while (!shutdown) {
        key = watcher.take();
        for (WatchEvent<?> event : key.pollEvents()) {
          if (event.kind() == ENTRY_MODIFY) {
            System.out.println("Home dir changed!");
          }
        }
View Full Code Here

TOP

Related Classes of java.nio.file.WatchService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.