Class DirectoryWatcher

  • All Implemented Interfaces:
    java.lang.Runnable

    public class DirectoryWatcher
    extends java.lang.Thread
    Utility class to watch directories for changes.
    Since:
    2.0
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  DirectoryWatcher.FileChangeListener
      Interface for FileChangeListeners
      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String SVN_DIR_NAME  
      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Constructor Summary

      Constructors 
      Constructor Description
      DirectoryWatcher()
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addListener​(DirectoryWatcher.FileChangeListener listener)
      Adds a file listener that can react to change events
      void addWatchDirectory​(java.io.File dir)
      Adds a directory to watch for the given file.
      void addWatchDirectory​(java.io.File dir, java.lang.String extension)
      Adds a directory to watch for the given file and extensions.
      void addWatchDirectory​(java.io.File dir, java.util.List<java.lang.String> fileExtensions)
      Adds a directory to watch for the given file and extensions.
      void addWatchFile​(java.io.File fileToWatch)
      Adds a file to the watch list
      void removeListener​(DirectoryWatcher.FileChangeListener listener)
      Removes a file listener from the current list
      void run()  
      void setActive​(boolean active)
      Sets whether to stop the directory watcher
      void setSleepTime​(long sleepTime)
      Sets the amount of time to sleep between checks
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • DirectoryWatcher

        public DirectoryWatcher()
        Constructor. Automatically selects the best means of watching for file system changes.
    • Method Detail

      • setActive

        public void setActive​(boolean active)
        Sets whether to stop the directory watcher
        Parameters:
        active - False if you want to stop watching
      • setSleepTime

        public void setSleepTime​(long sleepTime)
        Sets the amount of time to sleep between checks
        Parameters:
        sleepTime - The sleep time
      • addListener

        public void addListener​(DirectoryWatcher.FileChangeListener listener)
        Adds a file listener that can react to change events
        Parameters:
        listener - The file listener
      • removeListener

        public void removeListener​(DirectoryWatcher.FileChangeListener listener)
        Removes a file listener from the current list
        Parameters:
        listener - The file listener
      • addWatchFile

        public void addWatchFile​(java.io.File fileToWatch)
        Adds a file to the watch list
        Parameters:
        fileToWatch - The file to watch
      • addWatchDirectory

        public void addWatchDirectory​(java.io.File dir,
                                      java.util.List<java.lang.String> fileExtensions)
        Adds a directory to watch for the given file and extensions.
        Parameters:
        dir - The directory
        fileExtensions - The extensions
      • addWatchDirectory

        public void addWatchDirectory​(java.io.File dir)
        Adds a directory to watch for the given file. All files and subdirectories in the directory will be watched.
        Parameters:
        dir - The directory
      • addWatchDirectory

        public void addWatchDirectory​(java.io.File dir,
                                      java.lang.String extension)
        Adds a directory to watch for the given file and extensions.
        Parameters:
        dir - The directory
        extension - The extension
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread