Class AgeFileFilter
java.lang.Object
org.apache.commons.vfs2.filter.AgeFileFilter
- All Implemented Interfaces:
Serializable, FileFilter
Filters files based on a cutoff time, can filter either newer files or files
equal to or older.
For example, to print all files and directories in the current directory older than one day:
FileSystemManager fsManager = VFS.getManager();
FileObject dir = fsManager.toFileObject(new File("."));
// We are interested in files older than one day
long cutoff = System.currentTimeMillis() - (24 * 60 * 60 * 1000);
AgeFileFilter filter = new AgeFileFilter(cutoff);
FileObject[] files = dir.findFiles(new FileFilterSelector(filter));
for (int i = 0; i < files.length; i++) {
System.out.println(files[i]);
}
- Since:
- 2.4
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanWhether the files accepted will be older or newer.private final longThe cutoff time threshold.private static final long -
Constructor Summary
ConstructorsConstructorDescriptionAgeFileFilter(long cutoff) Constructs a new age file filter for files equal to or older than a certain cutoff.AgeFileFilter(long cutoff, boolean acceptOlder) Constructs a new age file filter for files on any one side of a certain cutoff.AgeFileFilter(Date cutoffDate) Constructs a new age file filter for files older than (at or before) a certain cutoff date.AgeFileFilter(Date cutoffDate, boolean acceptOlder) Constructs a new age file filter for files on any one side of a certain cutoff date.AgeFileFilter(FileObject cutoffReference) Constructs a new age file filter for files older than (at or before) a certain File (whose last modification time will be used as reference).AgeFileFilter(FileObject cutoffReference, boolean acceptOlder) Constructs a new age file filter for files on any one side of a certain File (whose last modification time will be used as reference). -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccept(FileSelectInfo fileInfo) Checks to see if the last modification of the file matches cutoff favorably.private static booleanisFileNewer(FileObject fileObject, long timeMillis) Tests if the specifiedFileis newer than the specified time reference.toString()Provide a String representaion of this file filter.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
acceptOlder
private final boolean acceptOlderWhether the files accepted will be older or newer. -
cutoff
private final long cutoffThe cutoff time threshold.
-
-
Constructor Details
-
AgeFileFilter
Constructs a new age file filter for files older than (at or before) a certain cutoff date.- Parameters:
cutoffDate- the threshold age of the files
-
AgeFileFilter
Constructs a new age file filter for files on any one side of a certain cutoff date.- Parameters:
cutoffDate- the threshold age of the filesacceptOlder- if true, older files (at or before the cutoff) are accepted, else newer ones (after the cutoff).
-
AgeFileFilter
Constructs a new age file filter for files older than (at or before) a certain File (whose last modification time will be used as reference).- Parameters:
cutoffReference- the file whose last modification time is usesd as the threshold age of the files- Throws:
FileSystemException- Error reading the last modification time from the reference file object.
-
AgeFileFilter
Constructs a new age file filter for files on any one side of a certain File (whose last modification time will be used as reference).- Parameters:
cutoffReference- the file whose last modification time is usesd as the threshold age of the filesacceptOlder- if true, older files (at or before the cutoff) are accepted, else newer ones (after the cutoff).- Throws:
FileSystemException- Error reading the last modification time from the reference file object.
-
AgeFileFilter
public AgeFileFilter(long cutoff) Constructs a new age file filter for files equal to or older than a certain cutoff.- Parameters:
cutoff- the threshold age of the files
-
AgeFileFilter
public AgeFileFilter(long cutoff, boolean acceptOlder) Constructs a new age file filter for files on any one side of a certain cutoff.- Parameters:
cutoff- the threshold age of the filesacceptOlder- if true, older files (at or before the cutoff) are accepted, else newer ones (after the cutoff).
-
-
Method Details
-
isFileNewer
private static boolean isFileNewer(FileObject fileObject, long timeMillis) throws FileSystemException Tests if the specifiedFileis newer than the specified time reference.- Parameters:
fileObject- theFileof which the modification date must be compared, must not benulltimeMillis- the time reference measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)- Returns:
- true if the
Fileexists and has been modified after the given time reference. - Throws:
FileSystemException- Thrown for file system errors.IllegalArgumentException- if the file isnull
-
accept
Checks to see if the last modification of the file matches cutoff favorably.If last modification time equals cutoff and newer files are required, file IS NOT selected. If last modification time equals cutoff and older files are required, file IS selected.
- Specified by:
acceptin interfaceFileFilter- Parameters:
fileInfo- the File to check- Returns:
- true if the file name matches
- Throws:
FileSystemException- Thrown for file system errors.
-
toString
-