Package org.apache.commons.io.filefilter
Class AgeFileFilter
java.lang.Object
org.apache.commons.io.filefilter.AbstractFileFilter
org.apache.commons.io.filefilter.AgeFileFilter
- All Implemented Interfaces:
FileFilter,FilenameFilter,Serializable,IOFileFilter
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:
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]);
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanWhether the files accepted will be older or newer.private final longThe cutoff time threshold.private static final longFields inherited from interface org.apache.commons.io.filefilter.IOFileFilter
EMPTY_STRING_ARRAY -
Constructor Summary
ConstructorsConstructorDescriptionAgeFileFilter(long cutoff) Constructs a new age file filter for files equal to or older than a certain cutoffAgeFileFilter(long cutoff, boolean acceptOlder) Constructs a new age file filter for files on any one side of a certain cutoff.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).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).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. -
Method Summary
Methods inherited from class org.apache.commons.io.filefilter.AbstractFileFilter
accept
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
cutoff
private final long cutoffThe cutoff time threshold. -
acceptOlder
private final boolean acceptOlderWhether the files accepted will be older or newer.
-
-
Constructor Details
-
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).
-
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 used as the threshold age of the files
-
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 used as 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
-
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- Specified by:
acceptin interfaceIOFileFilter- Overrides:
acceptin classAbstractFileFilter- Parameters:
file- the File to check- Returns:
- true if the file name matches
-
toString
Provide a String representation of this file filter.- Overrides:
toStringin classAbstractFileFilter- Returns:
- a String representation
-