AbstractDirectoryWatcher (Grails 6.0.0)

Package: org.grails.io.watch

## [Java] Class AbstractDirectoryWatcher

- org.grails.io.watch.AbstractDirectoryWatcher

- All Implemented Interfaces and Traits:
    java.lang.Runnable

      abstract class AbstractDirectoryWatcher
      extends java.lang.Object
      implements java.lang.Runnable

  Backend for DirectoryWatcher

  Authors:
    Craig Andrews
  Since:
    2.4
  See Also:
    WatchServiceDirectoryWatcher
    PollingDirectoryWatcher
    DirectoryWatcher

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `protected boolean` | `active` |
    `private java.util.List<DirectoryWatcher.FileChangeListener>` | `listeners` |
    `protected long` | `sleepTime` |

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `addListener(FileChangeListener listener)` Adds a file listener that can react to change events
    `` | `public abstract void` | `addWatchDirectory(java.io.File dir, java.util.List<java.lang.String> fileExtensions)` Adds a directory to watch for the given file and extensions.
    `` | `public abstract void` | `addWatchFile(java.io.File fileToWatch)` Adds a file to the watch list
    `` | `protected void` | `fireOnChange(java.io.File file)`
    `` | `protected void` | `fireOnNew(java.io.File file)`
    `` | `public static java.lang.String` | `getFilenameExtension(java.lang.String path)` Extract the filename extension from the given path, e.g.
    `` | `protected boolean` | `isValidDirectoryToMonitor(java.io.File file)`
    `` | `protected boolean` | `isValidFileToMonitor(java.io.File file, java.util.Collection<java.lang.String> fileExtensions)`
    `` | `public void` | `removeListener(FileChangeListener listener)` Removes a file listener from the current list
    `` | `public void` | `setActive(boolean active)` Sets whether to stop the directory watcher
    `` | `public void` | `setSleepTime(long sleepTime)` Sets the amount of time to sleep between checks

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class java.lang.Object` | `java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()`

- - ### Field Detail

    - #### protected boolean active

    - #### private java.util.List<DirectoryWatcher.FileChangeListener> listeners

    - #### protected long sleepTime

  - ### Method Detail

    - #### public void addListener(FileChangeListener listener)

      Adds a file listener that can react to change events

      Parameters:
        `listener` - The file listener

    - #### public abstract void addWatchDirectory(java.io.File dir, java.util.List<java.lang.String> fileExtensions)

      Adds a directory to watch for the given file and extensions. No String in the fileExtensions list can start with a dot (DirectoryWatcher guarantees that)

      Parameters:
        `dir` - The directory
        `fileExtensions` - The extensions

    - #### public abstract void addWatchFile(java.io.File fileToWatch)

      Adds a file to the watch list

      Parameters:
        `fileToWatch` - The file to watch

    - #### protected void fireOnChange(java.io.File file)

    - #### protected void fireOnNew(java.io.File file)

    - #### public static java.lang.String getFilenameExtension(java.lang.String path)

      Extract the filename extension from the given path, e.g. "mypath/myfile.txt" -> "txt".

      Parameters:
        `path` - the file path (may be `null`)
      Returns:
        the extracted filename extension, or `null` if none

    - #### protected boolean isValidDirectoryToMonitor(java.io.File file)

    - #### protected boolean isValidFileToMonitor(java.io.File file, java.util.Collection<java.lang.String> fileExtensions)

    - #### public void removeListener(FileChangeListener listener)

      Removes a file listener from the current list

      Parameters:
        `listener` - The file listener

    - #### public void setActive(boolean active)

      Sets whether to stop the directory watcher

      Parameters:
        `active` - False if you want to stop watching

    - #### public void setSleepTime(long sleepTime)

      Sets the amount of time to sleep between checks

      Parameters:
        `sleepTime` - The sleep time