public final class FileWatcher
extends java.lang.Object
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.
| Modifier and Type | Class and Description |
|---|---|
static class |
FileWatcher.WatchingException |
| Constructor and Description |
|---|
FileWatcher()
Creates a new FileWatcher with a default exception handler and a default debounce time.
|
FileWatcher(java.util.function.Consumer<java.lang.Exception> exceptionHandler)
Creates a new FileWatcher with the default debounce time and the given exception handler.
|
FileWatcher(java.time.Duration debounceTime)
Creates a new FileWatcher with a default exception handler.
|
FileWatcher(java.time.Duration debounceTime,
java.util.function.Consumer<java.lang.Throwable> exceptionHandler)
Creates a new FileWatcher with the given exception handler.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addWatch(java.io.File file,
java.lang.Runnable changeHandler)
Watches a file, if not already watched by this FileWatcher.
|
void |
addWatch(java.nio.file.Path file,
java.lang.Runnable changeHandler)
Watches a file, if not already watched by this FileWatcher.
|
static FileWatcher |
defaultInstance()
Gets the default, global instance of FileWatcher.
|
void |
removeWatch(java.io.File file)
Stops watching a file.
|
void |
removeWatch(java.nio.file.Path file)
Stops watching a file.
|
void |
setWatch(java.io.File file,
java.lang.Runnable changeHandler)
Watches a file.
|
void |
setWatch(java.nio.file.Path file,
java.lang.Runnable changeHandler)
Watches a file.
|
void |
stop()
Stops this FileWatcher.
|
public FileWatcher()
(e) -> e.printStackTrace();
The default debounce time is unspecified and may change in the future, but is typically
around 1 second or less.public FileWatcher(java.util.function.Consumer<java.lang.Exception> exceptionHandler)
The default debounce time is unspecified and may change in the future, but is typically around 1 second or less.
public FileWatcher(java.time.Duration debounceTime)
(e) -> e.printStackTrace();
debounceTime - hwo much time to wait after each modification of a file before triggering the change handlerpublic FileWatcher(java.time.Duration debounceTime,
java.util.function.Consumer<java.lang.Throwable> exceptionHandler)
debounceTime - delay between each call of the file's changeHandler.exceptionHandler - called when an exception occurs during the handling of file eventspublic static FileWatcher defaultInstance()
public void addWatch(java.io.File file,
java.lang.Runnable changeHandler)
file - the file to watchchangeHandler - the handler to call when the file is modifiedpublic void addWatch(java.nio.file.Path file,
java.lang.Runnable changeHandler)
file - the file to watchchangeHandler - the handler to call when the file is modifiedpublic void setWatch(java.io.File file,
java.lang.Runnable changeHandler)
file - the file to watchchangeHandler - the handler to call when the file is modifiedpublic void setWatch(java.nio.file.Path file,
java.lang.Runnable changeHandler)
file - the file to watchchangeHandler - the handler to call when the file is modifiedpublic void removeWatch(java.io.File file)
file - the file to stop watchingpublic void removeWatch(java.nio.file.Path file)
file - the file to stop watchingpublic void stop()