Class FileWatcher


  • public class FileWatcher
    extends Object
    • Constructor Detail

      • FileWatcher

        public FileWatcher()
    • Method Detail

      • addFile

        public void addFile​(File f)
        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

        public void removeFile​(File f)
        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

        public void addAll​(File dir,
                           FileFilter ff)
        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

        public void removeAll​(File dir)
        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

        public void removeAll​(FileFilter ff)
        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

        protected Map getFiles()
      • setFileDetails

        protected void setFileDetails​(File f,
                                      FileDetails fd)
      • setCheckRepeatTime

        public void setCheckRepeatTime​(long millis)
      • start

        public void start()
      • stop

        public void stop()
      • fireFileChange

        protected void fireFileChange​(File file,
                                      FileChangeEvent event,
                                      int types)
      • removeFileChangeListener

        public void removeFileChangeListener​(FileChangeListener f)
      • addFileChangeListener

        public void addFileChangeListener​(FileChangeListener f,
                                          int changeTypes)