AgeFileFilterpublic class AgeFileFilter extends AbstractFileFilter implements SerializableFilters 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:
File dir = new File(".");
// We are interested in files older than one day
long cutoff = System.currentTimeMillis() - (24 * 60 * 60 * 1000);
String[] files = dir.list( new AgeFileFilter(cutoff) );
for ( int i = 0; i < files.length; i++ ) {
System.out.println(files[i]);
}
|
Fields Summary |
---|
private final long | cutoffThe cutoff time threshold. | private final boolean | acceptOlderWhether the files accepted will be older or newer. |
Constructors Summary |
---|
public AgeFileFilter(long cutoff)Constructs a new age file filter for files equal to or older than
a certain cutoff
this(cutoff, true);
| public AgeFileFilter(long cutoff, boolean acceptOlder)Constructs a new age file filter for files on any one side
of a certain cutoff.
this.acceptOlder = acceptOlder;
this.cutoff = cutoff;
| public AgeFileFilter(Date cutoffDate)Constructs a new age file filter for files older than (at or before)
a certain cutoff date.
this(cutoffDate, true);
| public AgeFileFilter(Date cutoffDate, boolean acceptOlder)Constructs a new age file filter for files on any one side
of a certain cutoff date.
this(cutoffDate.getTime(), acceptOlder);
| public AgeFileFilter(File 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).
this(cutoffReference, true);
| public AgeFileFilter(File 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).
this(cutoffReference.lastModified(), acceptOlder);
|
Methods Summary |
---|
public boolean | accept(java.io.File file)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.
boolean newer = FileUtils.isFileNewer(file, cutoff);
return acceptOlder ? !newer : newer;
| public java.lang.String | toString()Provide a String representaion of this file filter.
String condition = acceptOlder ? "<=" : ">";
return super.toString() + "(" + condition + cutoff + ")";
|
|