Class FileModificationPollingMonitor

  • All Implemented Interfaces:
    FileModificationMonitor

    public class FileModificationPollingMonitor
    extends java.lang.Object
    implements FileModificationMonitor
    Monitors for modifications to the specified file using a polling-based mechanism and performs the specified action (in the form of a callback) upon detection of a file modification. Unlike FileModificationEventWatcher, which doesn't work for monitoring modifications to a file which is a symbolic link to another file, an object of this class works for such files as well. However, since this object uses a polling-based mechanism - unlike the event-based mechanism used by FileModificationEventWatcher, lists files on each iteration and compares the output, this object is highly likely to be less efficient than an object of FileModificationEventWatcher - CPU cycles-wise.
    • Constructor Summary

      Constructors 
      Constructor Description
      FileModificationPollingMonitor​(@NonNull java.nio.file.Path fileToWatch, @NonNull java.util.function.Consumer<java.io.File> callback)
      Creates a new instance.
    • Constructor Detail

      • FileModificationPollingMonitor

        public FileModificationPollingMonitor​(@NonNull
                                              @NonNull java.nio.file.Path fileToWatch,
                                              @NonNull
                                              @NonNull java.util.function.Consumer<java.io.File> callback)
                                       throws java.io.FileNotFoundException
        Creates a new instance.
        Parameters:
        fileToWatch - the file to watch
        callback - the callback to invoke when a modification to the fileToWatch is detected
        Throws:
        java.nio.file.InvalidPathException - if fileToWatch is invalid
        java.io.FileNotFoundException - when a file at specified path fileToWatch does not exist
        java.lang.NullPointerException - if either fileToWatch or callback is null