Package com.norconex.commons.lang.file
Class FileMonitor
- java.lang.Object
-
- com.norconex.commons.lang.file.FileMonitor
-
public final class FileMonitor extends Object
Class monitoring aFilefor changes and notifying all registeredIFileChangeListener.- Since:
- 1.3.0
- Author:
- Pascal Essiembre
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFileChangeListener(IFileChangeListener listener, File file, long period)Adds a monitored file with a FileChangeListener.voidaddFileChangeListener(IFileChangeListener listener, String fileName, long period)Adds a monitored file with aIFileChangeListener.protected voidfireFileChangeEvent(IFileChangeListener listener, File file)Fires notification that a file changed.static FileMonitorgetInstance()Gets the file monitor instance.voidremoveFileChangeListener(IFileChangeListener listener, File file)Remove the listener from the notification list.voidremoveFileChangeListener(IFileChangeListener listener, String fileName)Remove the listener from the notification list.
-
-
-
Method Detail
-
getInstance
public static FileMonitor getInstance()
Gets the file monitor instance.- Returns:
- file monitor instance
-
addFileChangeListener
public void addFileChangeListener(IFileChangeListener listener, String fileName, long period) throws FileNotFoundException
Adds a monitored file with aIFileChangeListener.- Parameters:
listener- listener to notify when the file changed.fileName- name of the file to monitor.period- polling period in milliseconds.- Throws:
FileNotFoundException- error with the file
-
addFileChangeListener
public void addFileChangeListener(IFileChangeListener listener, File file, long period) throws FileNotFoundException
Adds a monitored file with a FileChangeListener.- Parameters:
listener- listener to notify when the file changed.file- the file to monitor.period- polling period in milliseconds.- Throws:
FileNotFoundException- error with the file
-
removeFileChangeListener
public void removeFileChangeListener(IFileChangeListener listener, String fileName)
Remove the listener from the notification list.- Parameters:
listener- the listener to be removed.fileName- name of the file for which to remove the listener
-
removeFileChangeListener
public void removeFileChangeListener(IFileChangeListener listener, File file)
Remove the listener from the notification list.- Parameters:
listener- the listener to be removed.file- the file for which to remove the listener
-
fireFileChangeEvent
protected void fireFileChangeEvent(IFileChangeListener listener, File file)
Fires notification that a file changed.- Parameters:
listener- file change listenerfile- the file that changed
-
-