|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.springsource.util.io.FileSystemChecker
public final class FileSystemChecker
Checks a directory on the file system for modifications. Maintains a known state of the files to determine if the changes are new files, modified files or deleted files.
Modification notifications (FileSystemEvent
s) are published to a set of configured FileSystemListeners
. New listeners can be safely added at runtime.
By default, all files in the directory are monitored. Files can be excluded from monitoring using a regex pattern.
Concurrent Semantics
Nested Class Summary | |
---|---|
private static class |
FileSystemChecker.MonitorRecord
|
Field Summary | |
---|---|
private java.io.File |
checkDir
|
private java.lang.Object |
checkLock
|
private java.util.Map<java.lang.String,java.lang.Long> |
fileState
The files we know about -- with their last modified date (as a Long) are in fileState .Files that are changing or are new are monitored in monitorRecords . |
private java.io.FilenameFilter |
includeFilter
|
private java.util.List<FileSystemListener> |
listeners
|
private java.util.Map<java.lang.String,FileSystemChecker.MonitorRecord> |
monitorRecords
|
Constructor Summary | |
---|---|
FileSystemChecker(java.io.File checkDir)
Creates a new FileSystemChecker . |
|
FileSystemChecker(java.io.File checkDir,
java.lang.String excludePattern)
Creates a new FileSystemChecker . |
Method Summary | |
---|---|
void |
addListener(FileSystemListener listener)
Add a new FileSystemListener to this FileSystemChecker . |
void |
check()
Instructs this FileSystemChecker to check the configured directory and notifies any registered
listeners of changes to the directory files. |
private boolean |
isKnown(java.io.File file)
Is file known to us? (In fileState .) |
private java.lang.String |
key(java.io.File file)
Gets the record key for the supplied File . |
private java.lang.Long |
knownLastModified(java.io.File file)
Gets the recorded last modified timestamp for the supplied File . |
private java.io.File[] |
listCurrentDirFiles()
Lists the Files currently in the check directory. |
private void |
notifyListeners(java.lang.String file,
FileSystemEvent event)
|
private void |
populateInitialState()
Initialises known files ( fileState ) from the check directory and starts monitoring them. |
private void |
setKnownFileState(java.io.File file)
Sets the state of the supplied File into our known files map (fileState ). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final java.io.File checkDir
private final java.lang.Object checkLock
private final java.util.Map<java.lang.String,java.lang.Long> fileState
fileState
.monitorRecords
.
Invariant: all monitored files are in fileState
.fileState
and
not monitored can be assumed to have been notified about already.
private final java.util.Map<java.lang.String,FileSystemChecker.MonitorRecord> monitorRecords
private final java.util.List<FileSystemListener> listeners
private final java.io.FilenameFilter includeFilter
Constructor Detail |
---|
public FileSystemChecker(java.io.File checkDir)
FileSystemChecker
. Identifies changes on all files in checkDir
.
checkDir
- the directory to check.public FileSystemChecker(java.io.File checkDir, java.lang.String excludePattern)
FileSystemChecker
. Identifies changes to on all files, except thus that match
excludePattern
.
checkDir
- the directory to check -- File
must exist and be a directoryexcludePattern
- regular expression for files to exclude.Method Detail |
---|
public void addListener(FileSystemListener listener)
FileSystemListener
to this FileSystemChecker
.
listener
- the listener to add.public void check()
FileSystemChecker
to check the configured directory and notifies any registered
listeners of changes to the directory files.
private void notifyListeners(java.lang.String file, FileSystemEvent event)
private void populateInitialState()
fileState
) from the check directory and starts monitoring them.
private java.io.File[] listCurrentDirFiles()
Files
currently in the check directory.
Files
that are in the check directory.private void setKnownFileState(java.io.File file)
File
into our known files map (fileState
).
the
- File
to record state for.private java.lang.Long knownLastModified(java.io.File file)
File
.
file
- the File
to check for.
null
if no timestamp is recorded.private boolean isKnown(java.io.File file)
fileState
.)
file
- the File
to check for.
true
if in the map (domain), false
otherwise.private java.lang.String key(java.io.File file)
File
.
file
- the File
to get the key for.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |