com.jniwrapper.win32.io
Class FileSystemWatcher

java.lang.Object
  extended by com.jniwrapper.win32.io.FileSystemWatcher

public class FileSystemWatcher
extends java.lang.Object

FileSystemWatcher class is designed to listen for file system events in a specified folder with various watching parameters.

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.


Nested Class Summary
 class FileSystemWatcher.WatcherOptions
          WatcherOptions class determines a set of properties to configure the behavior of FileSystemWatcher.
 
Constructor Summary
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.
 
Method Summary
 void addFileSystemListener(FileSystemEventListener listener)
          Adds FileSystemEventListener
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileSystemWatcher

public FileSystemWatcher(java.lang.String path)
Creates a new instance to watch for modifications in a given folder. Sub-directories of the specified folder are not monitored by default.

Parameters:
path - a folder to watch

FileSystemWatcher

public FileSystemWatcher(java.lang.String path,
                         java.io.FileFilter fileFilter,
                         boolean watchSubree)
Creates a new instance to watch for modifications in a given folder.

Parameters:
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.

FileSystemWatcher

public FileSystemWatcher(java.lang.String path,
                         java.io.FileFilter fileFilter)
Creates a new instance to watch for modifications in a given folder.

Parameters:
path - the folder to watch.
fileFilter - specifies the files or folders to be watched.

FileSystemWatcher

public FileSystemWatcher(java.lang.String path,
                         boolean watchSubree)
Creates a new watcher to watch for modifications in a given path.

Parameters:
path - the folder to watch.
watchSubree - if true, sub-directories will also be monitored.
Method Detail

setStrategy

public void setStrategy(java.lang.Class strategyClass)
Sets up a custom watching strategy.

Parameters:
strategyClass - a custom strategy class derived from WatcherStrategy

createStrategy

protected WatcherStrategy createStrategy(java.lang.Class strategyClass)
Creates an instance of the watching strategy from the specified class.

Parameters:
strategyClass - a custom strategy class derived from WatcherStrategy
Returns:
an instance of the strategy.

getPath

public java.lang.String getPath()
Returns watched folder path

Returns:
Watched folder path

getFileFilter

public java.io.FileFilter getFileFilter()
Returns file filter

Returns:
File filter

isWatchSubree

public boolean isWatchSubree()
Returns true if the watcher is configured to watch the subtree, otherwise false.

Returns:
true if the watcher is configured to watch the subtree, otherwise false.

getOptions

public FileSystemWatcher.WatcherOptions getOptions()
Returns FileSystemWatcher.WatcherOptions that contains a set of notify filters.

Returns:
FileSystemWatcher.WatcherOptions that contains a set of notify filters.

addFileSystemListener

public void addFileSystemListener(FileSystemEventListener listener)
Adds FileSystemEventListener

Parameters:
listener - File system listener

removeFileSystemListener

public void removeFileSystemListener(FileSystemEventListener listener)
Removes FileSystemEventListener

Parameters:
listener - File system event listener

fireFileSystemEvent

protected void fireFileSystemEvent(FileSystemEvent event)
Sends specified event to all listeners that was added to this watcher

Parameters:
event - File system event

start

public void start()
           throws FileSystemException
Starts watching.

Throws:
FileSystemException

stop

public void stop()
          throws FileSystemException
Stops watching.

Throws:
FileSystemException

isWatching

public boolean isWatching()
Returns true if the watcher is watching a specified folder, otherwise false.

Returns:
true if the watcher is watching a specified folder, otherwise false.