public class FileSystemWatcher
extends java.lang.Object
It uses different watching strategies depending on OS.
For NT systems, it automatically sets up WinNTWatcherStrategy
and
for Win9x, it automatically sets up Win9xWatcherStrategy
. Also, it
can use other strategies derived from WatcherStrategy
.
Modifier and Type | Class and Description |
---|---|
class |
FileSystemWatcher.WatcherOptions
WatcherOptions class determines a set of properties to configure
the behavior of
FileSystemWatcher . |
Constructor and Description |
---|
FileSystemWatcher(java.lang.String path)
Creates a new instance to watch for modifications in a given folder.
|
FileSystemWatcher(java.lang.String path,
boolean watchSubree)
Creates a new watcher to watch for modifications in a given path.
|
FileSystemWatcher(java.lang.String path,
java.io.FileFilter fileFilter)
Creates a new instance to watch for modifications in a given folder.
|
FileSystemWatcher(java.lang.String path,
java.io.FileFilter fileFilter,
boolean watchSubree)
Creates a new instance to watch for modifications in a given folder.
|
Modifier and Type | Method and Description |
---|---|
void |
addFileSystemListener(FileSystemEventListener listener)
|
protected WatcherStrategy |
createStrategy(java.lang.Class strategyClass)
Creates an instance of the watching strategy from the specified class.
|
protected void |
fireFileSystemEvent(FileSystemEvent event)
Sends specified event to all listeners that was added to this watcher
|
java.io.FileFilter |
getFileFilter()
Returns file filter
|
FileSystemWatcher.WatcherOptions |
getOptions()
Returns
FileSystemWatcher.WatcherOptions that contains a set of notify filters. |
java.lang.String |
getPath()
Returns watched folder path
|
boolean |
isWatching()
Returns true if the watcher is watching a specified folder, otherwise false.
|
boolean |
isWatchSubree()
Returns true if the watcher is configured to watch the subtree, otherwise false.
|
void |
removeFileSystemListener(FileSystemEventListener listener)
Removes
FileSystemEventListener |
void |
setStrategy(java.lang.Class strategyClass)
Sets up a custom watching strategy.
|
void |
start()
Starts watching.
|
void |
stop()
Stops watching.
|
public FileSystemWatcher(java.lang.String path)
path
- a folder to watchpublic FileSystemWatcher(java.lang.String path, java.io.FileFilter fileFilter, boolean watchSubree)
path
- a folder to watch.fileFilter
- specifies the files or folders to be watched.watchSubree
- tells the watcher whether or not to watch the folder's subtree.public FileSystemWatcher(java.lang.String path, java.io.FileFilter fileFilter)
path
- the folder to watch.fileFilter
- specifies the files or folders to be watched.public FileSystemWatcher(java.lang.String path, boolean watchSubree)
path
- the folder to watch.watchSubree
- if true, sub-directories will also be monitored.public void setStrategy(java.lang.Class strategyClass)
strategyClass
- a custom strategy class derived from WatcherStrategy
protected WatcherStrategy createStrategy(java.lang.Class strategyClass)
strategyClass
- a custom strategy class derived from WatcherStrategy
public java.lang.String getPath()
public java.io.FileFilter getFileFilter()
public boolean isWatchSubree()
public FileSystemWatcher.WatcherOptions getOptions()
FileSystemWatcher.WatcherOptions
that contains a set of notify filters.FileSystemWatcher.WatcherOptions
that contains a set of notify filters.public void addFileSystemListener(FileSystemEventListener listener)
listener
- File system listenerpublic void removeFileSystemListener(FileSystemEventListener listener)
FileSystemEventListener
listener
- File system event listenerprotected void fireFileSystemEvent(FileSystemEvent event)
event
- File system eventpublic void start() throws FileSystemException
FileSystemException
public void stop() throws FileSystemException
FileSystemException
public boolean isWatching()