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:

Version: $Revision: 1.3 $ $Date: 2003/12/26 01:21:41 $

Field Summary
static StringACTION_CHANGED
static StringACTION_DELETED
static StringACTION_DUPLICATE
static StringACTION_MOVED
static StringACTION_NEW
static StringACTION_SAME
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
voidaddRecord(FileLogRecord rec)
Presumably added file too.
StringgetAttr(String key)
FileLogRecordgetRecord(File file)
Iteratoriterator()
Returns iterator over records in database.
StringputAttr(String key, String value)
voidsetHash(boolean b)
Sets file hashing, which computes a checksum on file contents.
voidsetHighSecurity(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.
voidupdate(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.
voidwrite()
Writes database to log file, presumably after update or ad hoc changes.

Field Detail

ACTION_CHANGED

public static final String ACTION_CHANGED

ACTION_DELETED

public static final String ACTION_DELETED

ACTION_DUPLICATE

public static final String ACTION_DUPLICATE

ACTION_MOVED

public static final String ACTION_MOVED

ACTION_NEW

public static final String ACTION_NEW

ACTION_SAME

public static final String ACTION_SAME

Constructor Detail

FileLog

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

Method Detail

addRecord

public void addRecord(FileLogRecord rec)
Presumably added file too.

getAttr

public String getAttr(String key)

getRecord

public FileLogRecord getRecord(File file)

iterator

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.

putAttr

public String putAttr(String key, String value)

setHash

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.

setHighSecurity

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.

update

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.

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.

write

public void write()
Writes database to log file, presumably after update or ad hoc changes.