Class FileWatcher
java.lang.Object
com.electronwill.nightconfig.core.file.FileWatcher
A FileWatcher can watch several files asynchronously.
New watches are added with the addWatch(Path, Runnable) method, which specifies the
task to execute when the file is modified.
This class is thread-safe.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new FileWatcher.FileWatcher(Consumer<Exception> exceptionHandler) Creates a new FileWatcher. -
Method Summary
Modifier and TypeMethodDescriptionvoidWatches a file, if not already watched by this FileWatcher.voidWatches a file, if not already watched by this FileWatcher.static FileWatcherGets the default, global instance of FileWatcher.voidremoveWatch(File file) Stops watching a file.voidremoveWatch(Path file) Stops watching a file.voidWatches a file.voidWatches a file.voidstop()Stops this FileWatcher.
-
Constructor Details
-
FileWatcher
public FileWatcher()Creates a new FileWatcher. The watcher is immediately functional, there is no need (and no way, actually) to start it manually. -
FileWatcher
Creates a new FileWatcher. The watcher is immediately functional, there is no need (and no way, actually) to start it manually.
-
-
Method Details
-
defaultInstance
Gets the default, global instance of FileWatcher.- Returns:
- the default FileWatcher
-
addWatch
Watches a file, if not already watched by this FileWatcher.- Parameters:
file- the file to watchchangeHandler- the handler to call when the file is modified- Throws:
IOException
-
addWatch
Watches a file, if not already watched by this FileWatcher.- Parameters:
file- the file to watchchangeHandler- the handler to call when the file is modified- Throws:
IOException
-
setWatch
Watches a file. If the file is already watched by this FileWatcher, its changeHandler is replaced.- Parameters:
file- the file to watchchangeHandler- the handler to call when the file is modified- Throws:
IOException
-
setWatch
Watches a file. If the file is already watched by this FileWatcher, its changeHandler is replaced.- Parameters:
file- the file to watchchangeHandler- the handler to call when the file is modified- Throws:
IOException
-
removeWatch
Stops watching a file.- Parameters:
file- the file to stop watching
-
removeWatch
Stops watching a file.- Parameters:
file- the file to stop watching
-
stop
Stops this FileWatcher. The underlying ressources (ie the WatchServices) are closed, and the file modification handlers won't be called anymore.- Throws:
IOException
-