Package name.pachler.nio.file

Examples of name.pachler.nio.file.Path


    public void stopTrack(File path, IFilesystemChangesListener listener) {
        Assert.isNotNull(path);
        Assert.isNotNull(listener);

        Path watchedPath = Paths.get(FileUtils.getFileAbsolutePath(path));

        if (log != null) {
            log.append("STOP Track: ").appendObject(path).append("Listener: ").appendObject(listener).append('\n');
        }
View Full Code Here


     */
    public void track(File path, IFilesystemChangesListener listener) {
        Assert.isNotNull(path);
        Assert.isNotNull(listener);

        Path watchedPath = Paths.get(FileUtils.getFileAbsolutePath(path));

        synchronized (lock) {
            EventsStackerRunnable stacker = pathToStacker.get(watchedPath);
            if (stacker != null) {
                //already being tracked -- or already in invalid list ;)
                stacker.list.add(listener);

                return;
            }

            if (log != null) {
                log.append("Track: ").appendObject(path).append("Listener: ").appendObject(listener).append('\n');
            }
            boolean add = true;
            WatchKey key = null;
            try {
                key = watchedPath.register(watchService, StandardWatchEventKind.ENTRY_CREATE,
                        StandardWatchEventKind.ENTRY_DELETE, StandardWatchEventKind.ENTRY_MODIFY,
                        StandardWatchEventKind.OVERFLOW, ExtendedWatchEventKind.KEY_INVALID);
            } catch (UnsupportedOperationException uox) {
                if (log != null) {
                    log.append("UnsupportedOperationException: ").appendObject(uox).append('\n');
View Full Code Here

                    System.out.println("watch service closed, terminating.");
                    break;
                }

                List<WatchEvent<?>> list;
                Path watchedPath;
                EventsStackerRunnable stacker;

                synchronized (lock) {
                    synchronized (keyToPathLock) {
                        watchedPath = keyToPath.get(signalledKey);
                    }
                    if (watchedPath == null) {
                        continue;
                    }

                    // get list of events from key
                    list = signalledKey.pollEvents();

                    stacker = pathToStacker.get(watchedPath);
                    if (stacker == null) {
                        //if the stacker does not exist, go on without rescheduling the key!
                        if (log != null) {
                            log.append("Stacker for: ").appendObject(watchedPath).append("is null\n");
                        }
                        continue;
                    }

                    runnables.add(stacker);

                    for (WatchEvent<?> e : list) {
                        Path context = (Path) e.context();
                        Path resolve = watchedPath.resolve(context);
                        File file = new File(resolve.toString());
                        Kind<?> kind = e.kind();
                        if (log != null) {
                            log.append("Event: ").appendObject(e).append('\n');
                        }
                        if (kind == StandardWatchEventKind.OVERFLOW) {
View Full Code Here

     */
  public WatchDir(File dir, WatchedCallback watched) throws IOException {
    this.watched = watched;
    this.keys = newHashMap();
    watchService = FileSystems.getDefault().newWatchService();
    Path watchedPath = Paths.get(dir.getAbsolutePath());
    WatchKey signalledKey = watchedPath.register(watchService, StandardWatchEventKind.ENTRY_CREATE, StandardWatchEventKind.ENTRY_DELETE, StandardWatchEventKind.ENTRY_MODIFY);
    // Store the path that we're watching, so we can later retrieve it and build a proper path to the file
    keys.put(signalledKey, watchedPath);
  }
View Full Code Here

      // key to be reported again by the watch service
      signalledKey.reset();

      // Retrieve the path for the files from the key created above; this is used by the
      // resolver below.
      Path dir = keys.get(signalledKey);
      try {
        for (WatchEvent<?> e : list) {
          if (e.kind() == StandardWatchEventKind.ENTRY_CREATE) {
            Path context = (Path) e.context();
            Path fullPath = dir.resolve(context);
            watched.fileAdded(new File(fullPath.toString()));
          } else if (e.kind() == StandardWatchEventKind.ENTRY_DELETE) {
            Path context = (Path) e.context();
            Path fullPath = dir.resolve(context);
            watched.fileDeleted(new File(fullPath.toString()));
          } else if (e.kind() == StandardWatchEventKind.ENTRY_MODIFY) {
            Path context = (Path) e.context();
            Path fullPath = dir.resolve(context);
            watched.fileModified(new File(fullPath.toString()));
          }
        }
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
View Full Code Here

TOP

Related Classes of name.pachler.nio.file.Path

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.