Package gw.fs.watcher
Class DirectoryWatcher
- java.lang.Object
-
- gw.fs.watcher.DirectoryWatcher
-
public class DirectoryWatcher extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DirectoryWatcher.FileEvent
-
Constructor Summary
Constructors Constructor Description DirectoryWatcher()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.void
stopWatching()
Close the watch service.void
watchDirectoryTree(Path dir)
Walk the directories under given path, and register a watcher for every directory.
-
-
-
Method Detail
-
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.
-
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.- Returns:
- FileEvent enum for each watched Path found, indicating the type of modification that happened.
-
-