public class AgeFileFilter extends java.lang.Object implements FileFilter, java.io.Serializable
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]); }
Modifier and Type | Field and Description |
---|---|
private boolean |
acceptOlder
Whether the files accepted will be older or newer.
|
private long |
cutoff
The cutoff time threshold.
|
private static long |
serialVersionUID |
Constructor and Description |
---|
AgeFileFilter(java.util.Date cutoffDate)
Constructs a new age file filter for files older than (at or before) a
certain cutoff date.
|
AgeFileFilter(java.util.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).
|
AgeFileFilter(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.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(FileSelectInfo fileInfo)
Checks to see if the last modification of the file matches cutoff favorably.
|
private static boolean |
isFileNewer(FileObject fileObject,
long timeMillis)
Tests if the specified
File is newer than the specified time
reference. |
java.lang.String |
toString()
Provide a String representaion of this file filter.
|
private static final long serialVersionUID
private final boolean acceptOlder
private final long cutoff
public AgeFileFilter(java.util.Date cutoffDate)
cutoffDate
- the threshold age of the filespublic AgeFileFilter(java.util.Date cutoffDate, boolean acceptOlder)
cutoffDate
- the threshold age of the filesacceptOlder
- if true, older files (at or before the cutoff) are
accepted, else newer ones (after the cutoff).public AgeFileFilter(FileObject cutoffReference) throws FileSystemException
cutoffReference
- the file whose last modification time is usesd as the
threshold age of the filesFileSystemException
- Error reading the last modification time from the
reference file object.public AgeFileFilter(FileObject cutoffReference, boolean acceptOlder) throws FileSystemException
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).FileSystemException
- Error reading the last modification time from the
reference file object.public AgeFileFilter(long cutoff)
cutoff
- the threshold age of the filespublic AgeFileFilter(long cutoff, boolean acceptOlder)
cutoff
- the threshold age of the filesacceptOlder
- if true, older files (at or before the cutoff) are
accepted, else newer ones (after the cutoff).private static boolean isFileNewer(FileObject fileObject, long timeMillis) throws FileSystemException
File
is newer than the specified time
reference.fileObject
- the File
of which the modification date must
be compared, must not be null
timeMillis
- the time reference measured in milliseconds since the epoch
(00:00:00 GMT, January 1, 1970)File
exists and has been modified after the
given time reference.FileSystemException
- Thrown for file system errors.java.lang.IllegalArgumentException
- if the file is null
public boolean accept(FileSelectInfo fileInfo) throws FileSystemException
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.
accept
in interface FileFilter
fileInfo
- the File to checkFileSystemException
- Thrown for file system errors.public java.lang.String toString()
toString
in class java.lang.Object