Package gw.fs.watcher

Class DirectoryWatcher

java.lang.Object
gw.fs.watcher.DirectoryWatcher

public class DirectoryWatcher extends Object
  • Field Details

  • Constructor Details

    • DirectoryWatcher

      public DirectoryWatcher()
  • Method Details

    • stopWatching

      public void stopWatching()
      Close the watch service. Releases resources. After calling, this instance becomes invalid and can't be used any more.
    • watchDirectoryTree

      public void watchDirectoryTree(Path dir)
      Walk the directories under given path, and register a watcher for every directory.
      Parameters:
      dir - the starting point under which to listen for changes, if it doesn't exist, do nothing.
    • watchDirectory

      private void watchDirectory(Path dir) throws IOException
      Throws:
      IOException
    • getChangesSinceLastTime

      public Map<Path,DirectoryWatcher.FileEvent> getChangesSinceLastTime()
      Checks all the watched directories (that are being kept in a map) for changes since the last call to this method.
    • If a file is already marked as CREATE, leave it as CREATE; if it's marked as DELETE, that's totally invalid, so just ignore that. If it's marked as MODIFY, no need to change it. So only put something in the map if it's not already in there.
    • If a create follows a delete, it means the editor deleted and re-created the file, and who knows what the contents are now, so it should be treated as a modification.
    • If the file was created, then deleted, then just ignore it entirely and remove the event.