Package com.gentlyweb.utils
Class FileWatcher
java.lang.Object
com.gentlyweb.utils.FileWatcher
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAll
(File dir, FileFilter ff) Add all the files in the specified directory.void
Add a file to be watched.void
void
addFileChangeListener
(FileChangeListener f, int changeTypes) void
clearAll()
Stop ALL files from being watched.protected void
fireFileChange
(File file, FileChangeEvent event, int types) protected Map
getFiles()
void
Remove all the files that we are watching that have the specified directory as given by the passed in File.void
removeAll
(FileFilter ff) Remove all the files from our list of watched files according to the FileFilter passed in.void
removeFile
(File f) Stop a file being watched.void
void
setCheckRepeatTime
(long millis) protected void
setFileDetails
(File f, FileDetails fd) void
start()
void
stop()
-
Constructor Details
-
FileWatcher
public FileWatcher()
-
-
Method Details
-
addFile
Add a file to be watched. If the file maps to a directory then we do nothing. Note: if you have already started the thread that contains this FileWatcher then the file will only be watched on the next "watch cycle". That is it may be longer than "sleepTime" before any changes to the file are noticed and reported. If we already have this file then we do nothing, in that case changes may be reported before "sleepTime" has elapsed.- Parameters:
f
- The file to add.
-
removeFile
Stop a file being watched. Note: if you have already started the thread that contains this FileWatcher then any existing changes to the file may still be reported since the watcher could be currently processing (or be about to process) the file.- Parameters:
f
- The file to remove.
-
clearAll
public void clearAll()Stop ALL files from being watched. Note: if you have already started the thread that contains this FileWatcher then any existing changes to the files may still be reported since the watcher could be currently processing one or more of the files. After the watchers current watch cycle then the files are guaranteed to no longer be watched. -
addAll
Add all the files in the specified directory. Use the FileFilter to provide filtering of files that we don't want to add. If the filter is null then we just add all the files. If dir points to a file then we do nothing.- Parameters:
dir
- The directory.ff
- The FileFilter to use to determine which files to accept/reject.
-
removeAll
Remove all the files that we are watching that have the specified directory as given by the passed in File. If the passed in File is not a directory then we do nothing. To perform the check we call: File.getParentFile () on each file and then do dir.equals (parentFile) to see if they are equal, if they are then we remove the file.- Parameters:
dir
- The parent directory of files that we want to remove.
-
removeAll
Remove all the files from our list of watched files according to the FileFilter passed in. This method is synchronized to prevent concurrent modification issues.- Parameters:
ff
- The FileFilter to determine what should be removed.
-
getFiles
-
setFileDetails
-
setCheckRepeatTime
public void setCheckRepeatTime(long millis) -
start
public void start() -
stop
public void stop() -
fireFileChange
-
removeFileChangeListener
-
addFileChangeListener
-
addFileChangeListener
-