Class FileFilterUtils
- Since:
- 1.0
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic IOFileFilterageFileFilter(long cutoffMillis) Returns a filter that returns true if the file was last modified before or at the specified cutoff time.static IOFileFilterageFileFilter(long cutoffMillis, boolean acceptOlder) Returns a filter that filters files based on a cutoff time.static IOFileFilterageFileFilter(File cutoffReference) Returns a filter that returns true if the file was last modified before or at the same time as the specified reference file.static IOFileFilterageFileFilter(File cutoffReference, boolean acceptOlder) Returns a filter that filters files based on a cutoff reference file.static IOFileFilterageFileFilter(Date cutoffDate) Returns a filter that returns true if the file was last modified before or at the specified cutoff date.static IOFileFilterageFileFilter(Date cutoffDate, boolean acceptOlder) Returns a filter that filters files based on a cutoff date.static IOFileFilterand(IOFileFilter... filters) Returns a filter that ANDs the specified filters.static IOFileFilterandFileFilter(IOFileFilter filter1, IOFileFilter filter2) Deprecated.static IOFileFilterasFileFilter(FileFilter filter) Returns anIOFileFilterthat wraps theFileFilterinstance.static IOFileFilterasFileFilter(FilenameFilter filter) Returns anIOFileFilterthat wraps theFilenameFilterinstance.static IOFileFilterReturns a filter that checks if the file is a directory.static IOFileFilterReturns a filter that always returns false.static IOFileFilterReturns a filter that checks if the file is a file (and not a directory).static File[]filter(IOFileFilter filter, File... files) Applies anIOFileFilterto the providedFileobjects.static File[]filter(IOFileFilter filter, Iterable<File> files) Applies anIOFileFilterto the providedFileobjects.filterList(IOFileFilter filter, File... files) Applies anIOFileFilterto the providedFileobjects.filterList(IOFileFilter filter, Iterable<File> files) Applies anIOFileFilterto the providedFileobjects.filterSet(IOFileFilter filter, File... files) Applies anIOFileFilterto the providedFileobjects.filterSet(IOFileFilter filter, Iterable<File> files) Applies anIOFileFilterto the providedFileobjects.static IOFileFiltermagicNumberFileFilter(byte[] magicNumber) Returns a filter that accepts files that begin with the provided magic number.static IOFileFiltermagicNumberFileFilter(byte[] magicNumber, long offset) Returns a filter that accepts files that contains the provided magic number at a specified offset within the file.static IOFileFiltermagicNumberFileFilter(String magicNumber) Returns a filter that accepts files that begin with the provided magic number.static IOFileFiltermagicNumberFileFilter(String magicNumber, long offset) Returns a filter that accepts files that contains the provided magic number at a specified offset within the file.static IOFileFiltermakeCVSAware(IOFileFilter filter) Decorates a filter to make it ignore CVS directories.static IOFileFiltermakeDirectoryOnly(IOFileFilter filter) Decorates a filter so that it only applies to directories and not to files.static IOFileFiltermakeFileOnly(IOFileFilter filter) Decorates a filter so that it only applies to files and not to directories.static IOFileFiltermakeSVNAware(IOFileFilter filter) Decorates a filter to make it ignore SVN directories.static IOFileFilternameFileFilter(String name) Returns a filter that returns true if the file name matches the specified text.static IOFileFilternameFileFilter(String name, IOCase ioCase) Returns a filter that returns true if the file name matches the specified text.static IOFileFilternotFileFilter(IOFileFilter filter) Returns a filter that NOTs the specified filter.static IOFileFilteror(IOFileFilter... filters) Returns a filter that ORs the specified filters.static IOFileFilterorFileFilter(IOFileFilter filter1, IOFileFilter filter2) Deprecated.static IOFileFilterprefixFileFilter(String prefix) Returns a filter that returns true if the file name starts with the specified text.static IOFileFilterprefixFileFilter(String prefix, IOCase ioCase) Returns a filter that returns true if the file name starts with the specified text.static IOFileFiltersizeFileFilter(long threshold) Returns a filter that returns true if the file is bigger than a certain size.static IOFileFiltersizeFileFilter(long threshold, boolean acceptLarger) Returns a filter that filters based on file size.static IOFileFiltersizeRangeFileFilter(long minSizeInclusive, long maxSizeInclusive) Returns a filter that accepts files whose size is >= minimum size and <= maximum size.static IOFileFiltersuffixFileFilter(String suffix) Returns a filter that returns true if the file name ends with the specified text.static IOFileFiltersuffixFileFilter(String suffix, IOCase ioCase) Returns a filter that returns true if the file name ends with the specified text.static List<IOFileFilter> toList(IOFileFilter... filters) Create a List of file filters.static IOFileFilterReturns a filter that always returns true.
- 
Constructor Details- 
FileFilterUtilspublic FileFilterUtils()FileFilterUtils is not normally instantiated.
 
- 
- 
Method Details- 
ageFileFilterReturns a filter that returns true if the file was last modified before or at the specified cutoff date.- Parameters:
- cutoffDate- the time threshold
- Returns:
- an appropriately configured age file filter
- Since:
- 1.2
- See Also:
 
- 
ageFileFilterReturns a filter that filters files based on a cutoff date.- Parameters:
- cutoffDate- the time threshold
- acceptOlder- if true, older files get accepted, if false, newer
- Returns:
- an appropriately configured age file filter
- Since:
- 1.2
- See Also:
 
- 
ageFileFilterReturns a filter that returns true if the file was last modified before or at the same time as the specified reference file.- Parameters:
- cutoffReference- the file whose last modification time is used as the threshold age of the files
- Returns:
- an appropriately configured age file filter
- Since:
- 1.2
- See Also:
 
- 
ageFileFilterReturns a filter that filters files based on a cutoff reference file.- Parameters:
- cutoffReference- the file whose last modification time is used as the threshold age of the files
- acceptOlder- if true, older files get accepted, if false, newer
- Returns:
- an appropriately configured age file filter
- Since:
- 1.2
- See Also:
 
- 
ageFileFilterReturns a filter that returns true if the file was last modified before or at the specified cutoff time.- Parameters:
- cutoffMillis- the time threshold
- Returns:
- an appropriately configured age file filter
- Since:
- 1.2
- See Also:
 
- 
ageFileFilterReturns a filter that filters files based on a cutoff time.- Parameters:
- cutoffMillis- the time threshold
- acceptOlder- if true, older files get accepted, if false, newer
- Returns:
- an appropriately configured age file filter
- Since:
- 1.2
- See Also:
 
- 
andReturns a filter that ANDs the specified filters.- Parameters:
- filters- the IOFileFilters that will be ANDed together.
- Returns:
- a filter that ANDs the specified filters
- Throws:
- IllegalArgumentException- if the filters are null or contain a null value.
- Since:
- 2.0
- See Also:
 
- 
andFileFilterDeprecated.Returns a filter that ANDs the two specified filters.- Parameters:
- filter1- the first filter
- filter2- the second filter
- Returns:
- a filter that ANDs the two specified filters
- See Also:
 
- 
asFileFilterReturns anIOFileFilterthat wraps theFileFilterinstance.- Parameters:
- filter- the filter to be wrapped
- Returns:
- a new filter that implements IOFileFilter
- See Also:
 
- 
asFileFilterReturns anIOFileFilterthat wraps theFilenameFilterinstance.- Parameters:
- filter- the filter to be wrapped
- Returns:
- a new filter that implements IOFileFilter
- See Also:
 
- 
directoryFileFilterReturns a filter that checks if the file is a directory.- Returns:
- file filter that accepts only directories and not files
- See Also:
 
- 
falseFileFilterReturns a filter that always returns false.- Returns:
- a false filter
- See Also:
 
- 
fileFileFilterReturns a filter that checks if the file is a file (and not a directory).- Returns:
- file filter that accepts only files and not directories
- See Also:
 
- 
filterApplies an IOFileFilterto the providedFileobjects. The resulting array is a subset of the original file list that matches the provided filter.Set<File> allFiles = ... Set<File> javaFiles = FileFilterUtils.filterSet(allFiles, FileFilterUtils.suffixFileFilter(".java"));- Parameters:
- filter- the filter to apply to the set of files.
- files- the array of files to apply the filter to.
- Returns:
- a subset of filesthat is accepted by the file filter.
- Throws:
- NullPointerException- if the filter is- nullor- filescontains a- nullvalue.
- Since:
- 2.0
 
- 
filterApplies an IOFileFilterto the providedFileobjects. The resulting array is a subset of the original file list that matches the provided filter.The Setreturned by this method is not guaranteed to be thread safe.Set<File> allFiles = ... Set<File> javaFiles = FileFilterUtils.filterSet(allFiles, FileFilterUtils.suffixFileFilter(".java"));- Parameters:
- filter- the filter to apply to the set of files.
- files- the array of files to apply the filter to.
- Returns:
- a subset of filesthat is accepted by the file filter.
- Throws:
- IllegalArgumentException- if the filter is- nullor- filescontains a- nullvalue.
- Since:
- 2.0
 
- 
filterListApplies an IOFileFilterto the providedFileobjects. The resulting list is a subset of the original files that matches the provided filter.The Listreturned by this method is not guaranteed to be thread safe.List<File> filesAndDirectories = ... List<File> directories = FileFilterUtils.filterList(filesAndDirectories, FileFilterUtils.directoryFileFilter());- Parameters:
- filter- the filter to apply to each files in the list.
- files- the collection of files to apply the filter to.
- Returns:
- a subset of filesthat is accepted by the file filter.
- Throws:
- IllegalArgumentException- if the filter is- nullor- filescontains a- nullvalue.
- Since:
- 2.0
 
- 
filterListApplies an IOFileFilterto the providedFileobjects. The resulting list is a subset of the original files that matches the provided filter.The Listreturned by this method is not guaranteed to be thread safe.List<File> filesAndDirectories = ... List<File> directories = FileFilterUtils.filterList(filesAndDirectories, FileFilterUtils.directoryFileFilter());- Parameters:
- filter- the filter to apply to each files in the list.
- files- the collection of files to apply the filter to.
- Returns:
- a subset of filesthat is accepted by the file filter.
- Throws:
- IllegalArgumentException- if the filter is- null
- Since:
- 2.0
 
- 
filterSetApplies an IOFileFilterto the providedFileobjects. The resulting set is a subset of the original file list that matches the provided filter.The Setreturned by this method is not guaranteed to be thread safe.Set<File> allFiles = ... Set<File> javaFiles = FileFilterUtils.filterSet(allFiles, FileFilterUtils.suffixFileFilter(".java"));- Parameters:
- filter- the filter to apply to the set of files.
- files- the collection of files to apply the filter to.
- Returns:
- a subset of filesthat is accepted by the file filter.
- Throws:
- IllegalArgumentException- if the filter is- nullor- filescontains a- nullvalue.
- Since:
- 2.0
 
- 
filterSetApplies an IOFileFilterto the providedFileobjects. The resulting set is a subset of the original file list that matches the provided filter.The Setreturned by this method is not guaranteed to be thread safe.Set<File> allFiles = ... Set<File> javaFiles = FileFilterUtils.filterSet(allFiles, FileFilterUtils.suffixFileFilter(".java"));- Parameters:
- filter- the filter to apply to the set of files.
- files- the collection of files to apply the filter to.
- Returns:
- a subset of filesthat is accepted by the file filter.
- Throws:
- IllegalArgumentException- if the filter is- null
- Since:
- 2.0
 
- 
magicNumberFileFilterReturns a filter that accepts files that begin with the provided magic number.- Parameters:
- magicNumber- the magic number (byte sequence) to match at the beginning of each file.
- Returns:
- an IOFileFilter that accepts files beginning with the provided magic number.
- Throws:
- IllegalArgumentException- if- magicNumberis- nullor is of length zero.
- Since:
- 2.0
- See Also:
 
- 
magicNumberFileFilterReturns a filter that accepts files that contains the provided magic number at a specified offset within the file.- Parameters:
- magicNumber- the magic number (byte sequence) to match at the provided offset in each file.
- offset- the offset within the files to look for the magic number.
- Returns:
- an IOFileFilter that accepts files containing the magic number at the specified offset.
- Throws:
- IllegalArgumentException- if- magicNumberis- null, or contains no bytes, or- offsetis a negative number.
- Since:
- 2.0
- See Also:
 
- 
magicNumberFileFilterReturns a filter that accepts files that begin with the provided magic number.- Parameters:
- magicNumber- the magic number (byte sequence) to match at the beginning of each file.
- Returns:
- an IOFileFilter that accepts files beginning with the provided magic number.
- Throws:
- IllegalArgumentException- if- magicNumberis- nullor the empty String.
- Since:
- 2.0
- See Also:
 
- 
magicNumberFileFilterReturns a filter that accepts files that contains the provided magic number at a specified offset within the file.- Parameters:
- magicNumber- the magic number (byte sequence) to match at the provided offset in each file.
- offset- the offset within the files to look for the magic number.
- Returns:
- an IOFileFilter that accepts files containing the magic number at the specified offset.
- Throws:
- IllegalArgumentException- if- magicNumberis- nullor the empty String, or if offset is a negative number.
- Since:
- 2.0
- See Also:
 
- 
makeCVSAwareDecorates a filter to make it ignore CVS directories. Passing innullwill return a filter that accepts everything except CVS directories.- Parameters:
- filter- the filter to decorate, null means an unrestricted filter
- Returns:
- the decorated filter, never null
- Since:
- 1.1 (method existed but had a bug in 1.0)
 
- 
makeDirectoryOnlyDecorates a filter so that it only applies to directories and not to files.- Parameters:
- filter- the filter to decorate, null means an unrestricted filter
- Returns:
- the decorated filter, never null
- Since:
- 1.3
- See Also:
 
- 
makeFileOnlyDecorates a filter so that it only applies to files and not to directories.- Parameters:
- filter- the filter to decorate, null means an unrestricted filter
- Returns:
- the decorated filter, never null
- Since:
- 1.3
- See Also:
 
- 
makeSVNAwareDecorates a filter to make it ignore SVN directories. Passing innullwill return a filter that accepts everything except SVN directories.- Parameters:
- filter- the filter to decorate, null means an unrestricted filter
- Returns:
- the decorated filter, never null
- Since:
- 1.1
 
- 
nameFileFilterReturns a filter that returns true if the file name matches the specified text.- Parameters:
- name- the file name
- Returns:
- a name checking filter
- See Also:
 
- 
nameFileFilterReturns a filter that returns true if the file name matches the specified text.- Parameters:
- name- the file name
- ioCase- how to handle case sensitivity, null means case-sensitive
- Returns:
- a name checking filter
- Since:
- 2.0
- See Also:
 
- 
notFileFilterReturns a filter that NOTs the specified filter.- Parameters:
- filter- the filter to invert
- Returns:
- a filter that NOTs the specified filter
- See Also:
 
- 
orReturns a filter that ORs the specified filters.- Parameters:
- filters- the IOFileFilters that will be ORed together.
- Returns:
- a filter that ORs the specified filters
- Throws:
- IllegalArgumentException- if the filters are null or contain a null value.
- Since:
- 2.0
- See Also:
 
- 
orFileFilterDeprecated.Returns a filter that ORs the two specified filters.- Parameters:
- filter1- the first filter
- filter2- the second filter
- Returns:
- a filter that ORs the two specified filters
- See Also:
 
- 
prefixFileFilterReturns a filter that returns true if the file name starts with the specified text.- Parameters:
- prefix- the file name prefix
- Returns:
- a prefix checking filter
- See Also:
 
- 
prefixFileFilterReturns a filter that returns true if the file name starts with the specified text.- Parameters:
- prefix- the file name prefix
- ioCase- how to handle case sensitivity, null means case-sensitive
- Returns:
- a prefix checking filter
- Since:
- 2.0
- See Also:
 
- 
sizeFileFilterReturns a filter that returns true if the file is bigger than a certain size.- Parameters:
- threshold- the file size threshold
- Returns:
- an appropriately configured SizeFileFilter
- Since:
- 1.2
- See Also:
 
- 
sizeFileFilterReturns a filter that filters based on file size.- Parameters:
- threshold- the file size threshold
- acceptLarger- if true, larger files get accepted, if false, smaller
- Returns:
- an appropriately configured SizeFileFilter
- Since:
- 1.2
- See Also:
 
- 
sizeRangeFileFilterReturns a filter that accepts files whose size is >= minimum size and <= maximum size.- Parameters:
- minSizeInclusive- the minimum file size (inclusive)
- maxSizeInclusive- the maximum file size (inclusive)
- Returns:
- an appropriately configured IOFileFilter
- Since:
- 1.3
- See Also:
 
- 
suffixFileFilterReturns a filter that returns true if the file name ends with the specified text.- Parameters:
- suffix- the file name suffix
- Returns:
- a suffix checking filter
- See Also:
 
- 
suffixFileFilterReturns a filter that returns true if the file name ends with the specified text.- Parameters:
- suffix- the file name suffix
- ioCase- how to handle case sensitivity, null means case-sensitive
- Returns:
- a suffix checking filter
- Since:
- 2.0
- See Also:
 
- 
toListCreate a List of file filters.- Parameters:
- filters- The file filters
- Returns:
- The list of file filters
- Throws:
- NullPointerException- if the filters are null or contain a null value.
- Since:
- 2.0
 
- 
trueFileFilterReturns a filter that always returns true.- Returns:
- a true filter
- See Also:
 
 
- 
and(IOFileFilter...)