public class FileWatcher extends Thread implements AutoClosable:
Portable file watcher based on periodic filesystem metadata polling.
The watcher observes a single path and emits typed events when existence, modification timestamp or size changes. It is implemented in Klyn and uses the existing Path metadata API, so it works consistently across platforms.
import klyn.io
watcher = FileWatcher("app.log", 250)
watcher.updated += lambda(e: FileWatcherEvent): print("changed: " + e.path)| Modifier and Type | Member | Description |
|---|---|---|
| public event | changedchanged as FileWatcherEvent |
Emitted for every detected file state change. |
| public event | createdcreated as FileWatcherEvent |
Emitted when the watched file appears. |
| public event | deleteddeleted as FileWatcherEvent |
Emitted when the watched file disappears. |
| public event | modifiedmodified as FileWatcherEvent |
Emitted when an existing watched file changes size or timestamp. |
| public event | updatedupdated as FileWatcherEvent |
Emitted when an existing watched file changes size or timestamp. |
| Modifier and Type | Member | Description |
|---|---|---|
| public readonly property | isWatchingisWatching as Boolean: |
Returns true while the background watcher loop is running. |
| public readonly property | pathpath as Path: |
Watched path. |
| public property | pollIntervalMspollIntervalMs as Int: |
Polling interval in milliseconds. |
| Modifier and Type | Member | Description |
|---|---|---|
| public | FileWatcherFileWatcher(path as Path, pollIntervalMs as Int = 50): |
Creates a watcher for a Path instance. |
| public | FileWatcherFileWatcher(path as String, pollIntervalMs as Int = 50): |
Creates a watcher for a path string. |
| Modifier and Type | Member | Description |
|---|---|---|
| public | closeclose() as Void: |
AutoClosable support for try-with-resources. |
| public | pollpoll() as Boolean: |
Polls once and emits events if the file state changed. |
| public | resetBaselineresetBaseline() as Void: |
Resets the baseline without emitting events. |
| public override | runrun() as Void: |
Background watcher loop. |
| public override | startstart() as Void: |
Starts background polling. |
| public override | stopstop() as Void: |
Stops background polling. |