Class FileWatcher

java.lang.Object
com.seeq.utilities.FileWatcher

public class FileWatcher extends Object
Monitors a directory for changes to a specific file and notifies the listener of any changes to the file.
  • Constructor Details

    • FileWatcher

      public FileWatcher(Path directory, @Nullable String file, FileChangeListener listener, Duration debouncePeriod)
      Constructor for the file watcher. Note that start() must be called to begin watching for changes to the directory.
      Parameters:
      directory - The directory to watch for changes. Created if it does not exist.
      file - The name of the file to watch for changes. If null, the whole directory is monitored for changes.
      listener - The listener that is invoked upon the file being changed.
      debouncePeriod - The period to wait before notifying the listener. If an additional change happens during this period, then the debouncePeriod clock is reset and another debouncePeriod must elapse before the listener is notified.
  • Method Details

    • start

      public void start() throws IOException
      Start watching the API key file by spawning a new thread.
      Throws:
      IOException - Thrown when the directory cannot be created or watched.
    • stop

      public void stop()
      Stop this thread. The killing happens lazily, giving the running thread an opportunity to finish the work at hand.
    • isRunning

      public boolean isRunning()
      Determines whether or not the watcher service is running.
      Returns:
      True if the watcher is running, false otherwise