public class FileWatcherImpl extends Object implements ResourceWatcher
ResourceWatcher
implemnatation.
It watches a file and detects any new modification.
The file content that already exist before the watcher is launched is skipped.
Only file content addition is handled.Constructor and Description |
---|
FileWatcherImpl(WatchService watchService,
Path filePath,
OutputHandler outputHandler) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
run()
Launches a
WatchService and register the file's parent directory for events of type
StandardWatchEventKinds.ENTRY_MODIFY . |
@Inject public FileWatcherImpl(@NonNull WatchService watchService, @NonNull Path filePath, @NonNull OutputHandler outputHandler)
public void run()
WatchService
and register the file's parent directory for events of type
StandardWatchEventKinds.ENTRY_MODIFY
.
The events are filtered according to the filename. Only the file modications are handler.
A first step consists of couting the existing characters already present in the file before
registering the file for watching the modificatiion events.
At each modification event the existing characters are skipped and only the new added lines
are processed.run
in interface ResourceWatcher
public void close()
close
in interface Closeable
close
in interface AutoCloseable
Copyright © 2019. All rights reserved.