Package org.grails.io.watch
Class WatchServiceDirectoryWatcher
- java.lang.Object
-
- org.grails.io.watch.WatchServiceDirectoryWatcher
-
- All Implemented Interfaces:
java.lang.Runnable
public class WatchServiceDirectoryWatcher extends java.lang.ObjectImplementation of aAbstractDirectoryWatcherthat usesWatchService. This implementation is used for Java 7 and later.- Since:
- 2.4
- See Also:
WatchServiceDirectoryWatcher,DirectoryWatcher
-
-
Constructor Summary
Constructors Constructor Description WatchServiceDirectoryWatcher()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(DirectoryWatcher.FileChangeListener listener)Adds a file listener that can react to change eventsvoidaddWatchDirectory(java.io.File dir, java.util.List<java.lang.String> fileExtensions)Adds a directory to watch for the given file and extensions.voidaddWatchFile(java.io.File fileToWatch)Adds a file to the watch listprotected voidfireOnChange(java.io.File file)protected voidfireOnNew(java.io.File file)static java.lang.StringgetFilenameExtension(java.lang.String path)Extract the filename extension from the given path, e.g.protected booleanisValidDirectoryToMonitor(java.io.File file)protected booleanisValidFileToMonitor(java.io.File file, java.util.Collection<java.lang.String> fileExtensions)voidremoveListener(DirectoryWatcher.FileChangeListener listener)Removes a file listener from the current listvoidrun()voidsetActive(boolean active)Sets whether to stop the directory watchervoidsetSleepTime(long sleepTime)Sets the amount of time to sleep between checks
-
-
-
Method Detail
-
run
public void run()
-
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. No String in the fileExtensions list can start with a dot (DirectoryWatcher guarantees that)- Parameters:
dir- The directoryfileExtensions- The extensions
-
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
-
fireOnChange
protected void fireOnChange(java.io.File file)
-
fireOnNew
protected void fireOnNew(java.io.File file)
-
isValidDirectoryToMonitor
protected boolean isValidDirectoryToMonitor(java.io.File file)
-
isValidFileToMonitor
protected boolean isValidFileToMonitor(java.io.File file, java.util.Collection<java.lang.String> fileExtensions)
-
getFilenameExtension
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 (maybenull)- Returns:
- the extracted filename extension, or
nullif none
-
-