How DirectoryWatcher differs from standard WatchService
mainDirectoryWatcher provides several improvements over the standard JDK WatchService:
- Recursive Watching: It provides true recursive watching. On Windows, it uses
ExtendedWatchEventModifier.FILE_TREE. On Linux, it manually registers newWatchKeys for subdirectories as they are added. - Native macOS Support: It uses a JNA-based implementation for macOS to avoid the inefficient polling-based JDK implementation.
- Event Deduplication: It uses file hashing to filter out duplicate or redundant events (e.g., multiple modify events emitted by Windows for a single change).
- Path Resolution: On macOS, the implementation returns the full absolute path in notifications, so you do not need to resolve it against a
WatchKey.