phelps.io
Class FileLog
public
class
FileLog
extends Object
Maintain a list of files with associated client data and change notification.
The cilent can store arbitrary data in the log, outside of the file itself.
An observer client can notified of the status of files vis-a-vis database:
same, moved, changed, new, duplicate, or deleted.
Some possible uses:
- see what you've been up to in your home directory
- log changes in OS files to check for intrusions
- obtain a list of changed files for incremental backup
- cache an expensive computation derived from the file (phelps.awt.font.NFontManager does this with font names extracted from the many font files)
- update links in web pages after a site reorganization
- check for changes in some API's Javadoc
Version: $Revision: 1.3 $ $Date: 2003/12/26 01:21:41 $
Constructor Summary |
| FileLog(File log, String[] paths, boolean recurse, int dataversion)
If the log file doesn't exist, creates a new file log for the files in the directories paths, and their subdirectories if recurse is true .
|
Method Summary |
void | addRecord(FileLogRecord rec) Presumably added file too. |
String | getAttr(String key) |
FileLogRecord | getRecord(File file) |
Iterator | iterator()
Returns iterator over records in database.
|
String | putAttr(String key, String value) |
void | setHash(boolean b) Sets file hashing, which computes a checksum on file contents. |
void | setHighSecurity(boolean b) High security mode does not trust that if a file has the same modification time and length as before that it is necessarily unchanged. |
void | update(Observer observer, FileFilter filter)
Rreport to observer the current state of each file in the directory paths vis-a-vis the database:
same, new, changed, delted, moved, duplicate.
|
void | write()
Writes database to log file, presumably after update or ad hoc changes. |
public static final String ACTION_CHANGED
public static final String ACTION_DELETED
public static final String ACTION_DUPLICATE
public static final String ACTION_MOVED
public static final String ACTION_NEW
public static final String ACTION_SAME
public FileLog(File log, String[] paths, boolean recurse, int dataversion)
If the
log file doesn't exist, creates a new file log for the files in the directories
paths, and their subdirectories if
recurse is
true
.
If
log exists, opens it and sets the new paths, overriding whatever was used before (usually
paths and
recurse are identical).
If the stored data format version is less than
dataversion then all data is throw out, and a subsequent
FileLog will report all new files.
Parameters: log file to which to writ the log, null
for no persistence
Presumably added file too.
public String getAttr(String key)
public Iterator iterator()
Returns iterator over records in database.
Records should not be directly added or removed from the database while iterating;
however records can be mutated or remove via the iterator.
public String putAttr(String key, String value)
public void setHash(boolean b)
Sets file hashing, which computes a checksum on file contents. Hashing takes time, but enables moved and duplicate reports. Default: true
.
public void setHighSecurity(boolean b)
High security mode does not trust that if a file has the same modification time and length as before that it is necessarily unchanged. Default: false
.
public void update(Observer observer, FileFilter filter)
Rreport to
observer the current state of each file in the directory paths vis-a-vis the database:
same, new, changed, delted, moved, duplicate.
Reports sent to the
observer's
update
method as an
Object[]
argument
with the action code and one or more
FileLogRecords.
- Same. The database reports [ACTION_SAME old] to the observer. Often observers ignore these reports.
- New. The database adds a basic record (without user data) and reports [ACTION_NEW new] to the observer. Often observers set the associated data at this time.
- Changed. The database updates the file metadata and reports [ACTION_CHANGED old new] to the observer.
- Deleted. The database deletes the file and reports [ACTION_DELETED old] to the observer.
- Moved. The database moves the record to the new position and reports [ACTION_MOVED old new] to the observer. This option is not available if hashing is turned off.
- Duplicate. The database reports [ACTION_DUPLICATE existing new] to the observer. This option is not available if hashing is turned off.
Upon receiving a change notice, the observer can update the database with new user data,
or reverse the default action,
or ignore certain classes of changes.
Can change any data, even checksum; may want to normalize data and compute checksum on that.
The observer can be null
if no change reports are desired.
Ordinarily clients will write the results back to disk.
public void write()
Writes database to log file, presumably after
update or ad hoc changes.