public class FileFilterUtils extends Object
| Constructor and Description |
|---|
FileFilterUtils()
FileFilterUtils is not normally instantiated.
|
| Modifier and Type | Method and Description |
|---|---|
static IOFileFilter |
ageFileFilter(Date cutoffDate)
Returns a filter that returns true if the file was last modified before
or at the specified cutoff date.
|
static IOFileFilter |
ageFileFilter(Date cutoffDate,
boolean acceptOlder)
Returns a filter that filters files based on a cutoff date.
|
static IOFileFilter |
ageFileFilter(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 IOFileFilter |
ageFileFilter(File cutoffReference,
boolean acceptOlder)
Returns a filter that filters files based on a cutoff reference file.
|
static IOFileFilter |
ageFileFilter(long cutoff)
Returns a filter that returns true if the file was last modified before
or at the specified cutoff time.
|
static IOFileFilter |
ageFileFilter(long cutoff,
boolean acceptOlder)
Returns a filter that filters files based on a cutoff time.
|
static IOFileFilter |
and(IOFileFilter... filters)
Returns a filter that ANDs the specified filters.
|
static IOFileFilter |
andFileFilter(IOFileFilter filter1,
IOFileFilter filter2)
Deprecated.
|
static IOFileFilter |
asFileFilter(FileFilter filter)
Returns an
IOFileFilter that wraps the
FileFilter instance. |
static IOFileFilter |
asFileFilter(FilenameFilter filter)
Returns an
IOFileFilter that wraps the
FilenameFilter instance. |
static IOFileFilter |
directoryFileFilter()
Returns a filter that checks if the file is a directory.
|
static IOFileFilter |
falseFileFilter()
Returns a filter that always returns false.
|
static IOFileFilter |
fileFileFilter()
Returns a filter that checks if the file is a file (and not a directory).
|
static File[] |
filter(IOFileFilter filter,
File... files)
Applies an
IOFileFilter to the provided File
objects. |
static File[] |
filter(IOFileFilter filter,
Iterable<File> files)
Applies an
IOFileFilter to the provided File
objects. |
static List<File> |
filterList(IOFileFilter filter,
File... files)
Applies an
IOFileFilter to the provided File
objects. |
static List<File> |
filterList(IOFileFilter filter,
Iterable<File> files)
Applies an
IOFileFilter to the provided File
objects. |
static Set<File> |
filterSet(IOFileFilter filter,
File... files)
Applies an
IOFileFilter to the provided File
objects. |
static Set<File> |
filterSet(IOFileFilter filter,
Iterable<File> files)
Applies an
IOFileFilter to the provided File
objects. |
static IOFileFilter |
magicNumberFileFilter(byte[] magicNumber)
Returns a filter that accepts files that begin with the provided magic
number.
|
static IOFileFilter |
magicNumberFileFilter(byte[] magicNumber,
long offset)
Returns a filter that accepts files that contains the provided magic
number at a specified offset within the file.
|
static IOFileFilter |
magicNumberFileFilter(String magicNumber)
Returns a filter that accepts files that begin with the provided magic
number.
|
static IOFileFilter |
magicNumberFileFilter(String magicNumber,
long offset)
Returns a filter that accepts files that contains the provided magic
number at a specified offset within the file.
|
static IOFileFilter |
makeCVSAware(IOFileFilter filter)
Decorates a filter to make it ignore CVS directories.
|
static IOFileFilter |
makeDirectoryOnly(IOFileFilter filter)
Decorates a filter so that it only applies to directories and not to files.
|
static IOFileFilter |
makeFileOnly(IOFileFilter filter)
Decorates a filter so that it only applies to files and not to directories.
|
static IOFileFilter |
makeSVNAware(IOFileFilter filter)
Decorates a filter to make it ignore SVN directories.
|
static IOFileFilter |
nameFileFilter(String name)
Returns a filter that returns true if the file name matches the specified text.
|
static IOFileFilter |
nameFileFilter(String name,
IOCase caseSensitivity)
Returns a filter that returns true if the file name matches the specified text.
|
static IOFileFilter |
notFileFilter(IOFileFilter filter)
Returns a filter that NOTs the specified filter.
|
static IOFileFilter |
or(IOFileFilter... filters)
Returns a filter that ORs the specified filters.
|
static IOFileFilter |
orFileFilter(IOFileFilter filter1,
IOFileFilter filter2)
Deprecated.
|
static IOFileFilter |
prefixFileFilter(String prefix)
Returns a filter that returns true if the file name starts with the specified text.
|
static IOFileFilter |
prefixFileFilter(String prefix,
IOCase caseSensitivity)
Returns a filter that returns true if the file name starts with the specified text.
|
static IOFileFilter |
sizeFileFilter(long threshold)
Returns a filter that returns true if the file is bigger than a certain size.
|
static IOFileFilter |
sizeFileFilter(long threshold,
boolean acceptLarger)
Returns a filter that filters based on file size.
|
static IOFileFilter |
sizeRangeFileFilter(long minSizeInclusive,
long maxSizeInclusive)
Returns a filter that accepts files whose size is >= minimum size
and <= maximum size.
|
static IOFileFilter |
suffixFileFilter(String suffix)
Returns a filter that returns true if the file name ends with the specified text.
|
static IOFileFilter |
suffixFileFilter(String suffix,
IOCase caseSensitivity)
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 IOFileFilter |
trueFileFilter()
Returns a filter that always returns true.
|
public FileFilterUtils()
public static IOFileFilter ageFileFilter(Date cutoffDate)
cutoffDate - the time thresholdAgeFileFilterpublic static IOFileFilter ageFileFilter(Date cutoffDate, boolean acceptOlder)
cutoffDate - the time thresholdacceptOlder - if true, older files get accepted, if false, newerAgeFileFilterpublic static IOFileFilter ageFileFilter(File cutoffReference)
cutoffReference - the file whose last modification
time is used as the threshold age of the filesAgeFileFilterpublic static IOFileFilter ageFileFilter(File cutoffReference, boolean acceptOlder)
cutoffReference - the file whose last modification
time is used as the threshold age of the filesacceptOlder - if true, older files get accepted, if false, newerAgeFileFilterpublic static IOFileFilter ageFileFilter(long cutoff)
cutoff - the time thresholdAgeFileFilterpublic static IOFileFilter ageFileFilter(long cutoff, boolean acceptOlder)
cutoff - the time thresholdacceptOlder - if true, older files get accepted, if false, newerAgeFileFilterpublic static IOFileFilter and(IOFileFilter... filters)
filters - the IOFileFilters that will be ANDed together.IllegalArgumentException - if the filters are null or contain a
null value.AndFileFilter@Deprecated public static IOFileFilter andFileFilter(IOFileFilter filter1, IOFileFilter filter2)
and(IOFileFilter...)filter1 - the first filterfilter2 - the second filterand(IOFileFilter...),
AndFileFilterpublic static IOFileFilter asFileFilter(FileFilter filter)
IOFileFilter that wraps the
FileFilter instance.filter - the filter to be wrappedDelegateFileFilterpublic static IOFileFilter asFileFilter(FilenameFilter filter)
IOFileFilter that wraps the
FilenameFilter instance.filter - the filter to be wrappedDelegateFileFilterpublic static IOFileFilter directoryFileFilter()
DirectoryFileFilter.DIRECTORYpublic static IOFileFilter falseFileFilter()
FalseFileFilter.FALSEpublic static IOFileFilter fileFileFilter()
FileFileFilter.INSTANCEpublic static File[] filter(IOFileFilter filter, File... files)
Applies an IOFileFilter to the provided File
objects. 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"));
filter - the filter to apply to the set of files.files - the array of files to apply the filter to.files that is accepted by the
file filter.IllegalArgumentException - if the filter is null
or files contains a null value.public static File[] filter(IOFileFilter filter, Iterable<File> files)
Applies an IOFileFilter to the provided File
objects. The resulting array is a subset of the original file list that
matches the provided filter.
The Set returned by this method is not guaranteed to be thread safe.
Set<File> allFiles = ...
Set<File> javaFiles = FileFilterUtils.filterSet(allFiles,
FileFilterUtils.suffixFileFilter(".java"));
filter - the filter to apply to the set of files.files - the array of files to apply the filter to.files that is accepted by the
file filter.IllegalArgumentException - if the filter is null
or files contains a null value.public static List<File> filterList(IOFileFilter filter, File... files)
Applies an IOFileFilter to the provided File
objects. The resulting list is a subset of the original files that
matches the provided filter.
The List returned by this method is not guaranteed to be thread safe.
List<File> filesAndDirectories = ...
List<File> directories = FileFilterUtils.filterList(filesAndDirectories,
FileFilterUtils.directoryFileFilter());
filter - the filter to apply to each files in the list.files - the collection of files to apply the filter to.files that is accepted by the
file filter.IllegalArgumentException - if the filter is null
or files contains a null value.public static List<File> filterList(IOFileFilter filter, Iterable<File> files)
Applies an IOFileFilter to the provided File
objects. The resulting list is a subset of the original files that
matches the provided filter.
The List returned by this method is not guaranteed to be thread safe.
List<File> filesAndDirectories = ...
List<File> directories = FileFilterUtils.filterList(filesAndDirectories,
FileFilterUtils.directoryFileFilter());
filter - the filter to apply to each files in the list.files - the collection of files to apply the filter to.files that is accepted by the
file filter.IllegalArgumentException - if the filter is nullpublic static Set<File> filterSet(IOFileFilter filter, File... files)
Applies an IOFileFilter to the provided File
objects. The resulting set is a subset of the original file list that
matches the provided filter.
The Set returned by this method is not guaranteed to be thread safe.
Set<File> allFiles = ...
Set<File> javaFiles = FileFilterUtils.filterSet(allFiles,
FileFilterUtils.suffixFileFilter(".java"));
filter - the filter to apply to the set of files.files - the collection of files to apply the filter to.files that is accepted by the
file filter.IllegalArgumentException - if the filter is null
or files contains a null value.public static Set<File> filterSet(IOFileFilter filter, Iterable<File> files)
Applies an IOFileFilter to the provided File
objects. The resulting set is a subset of the original file list that
matches the provided filter.
The Set returned by this method is not guaranteed to be thread safe.
Set<File> allFiles = ...
Set<File> javaFiles = FileFilterUtils.filterSet(allFiles,
FileFilterUtils.suffixFileFilter(".java"));
filter - the filter to apply to the set of files.files - the collection of files to apply the filter to.files that is accepted by the
file filter.IllegalArgumentException - if the filter is nullpublic static IOFileFilter magicNumberFileFilter(byte[] magicNumber)
magicNumber - the magic number (byte sequence) to match at the
beginning of each file.IllegalArgumentException - if magicNumber is
null or is of length zero.MagicNumberFileFilterpublic static IOFileFilter magicNumberFileFilter(byte[] magicNumber, long offset)
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.IllegalArgumentException - if magicNumber is
null, or contains no bytes, or offset
is a negative number.MagicNumberFileFilterpublic static IOFileFilter magicNumberFileFilter(String magicNumber)
magicNumber - the magic number (byte sequence) to match at the
beginning of each file.IllegalArgumentException - if magicNumber is
null or the empty String.MagicNumberFileFilterpublic static IOFileFilter magicNumberFileFilter(String magicNumber, long offset)
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.IllegalArgumentException - if magicNumber is
null or the empty String, or if offset is a
negative number.MagicNumberFileFilterpublic static IOFileFilter makeCVSAware(IOFileFilter filter)
null will return a filter that accepts everything
except CVS directories.filter - the filter to decorate, null means an unrestricted filterpublic static IOFileFilter makeDirectoryOnly(IOFileFilter filter)
filter - the filter to decorate, null means an unrestricted filterDirectoryFileFilter.DIRECTORYpublic static IOFileFilter makeFileOnly(IOFileFilter filter)
filter - the filter to decorate, null means an unrestricted filterFileFileFilter.INSTANCEpublic static IOFileFilter makeSVNAware(IOFileFilter filter)
null will return a filter that accepts everything
except SVN directories.filter - the filter to decorate, null means an unrestricted filterpublic static IOFileFilter nameFileFilter(String name)
name - the file nameNameFileFilterpublic static IOFileFilter nameFileFilter(String name, IOCase caseSensitivity)
name - the file namecaseSensitivity - how to handle case sensitivity, null means case-sensitiveNameFileFilterpublic static IOFileFilter notFileFilter(IOFileFilter filter)
filter - the filter to invertNotFileFilterpublic static IOFileFilter or(IOFileFilter... filters)
filters - the IOFileFilters that will be ORed together.IllegalArgumentException - if the filters are null or contain a
null value.OrFileFilter@Deprecated public static IOFileFilter orFileFilter(IOFileFilter filter1, IOFileFilter filter2)
or(IOFileFilter...)filter1 - the first filterfilter2 - the second filteror(IOFileFilter...),
OrFileFilterpublic static IOFileFilter prefixFileFilter(String prefix)
prefix - the file name prefixPrefixFileFilterpublic static IOFileFilter prefixFileFilter(String prefix, IOCase caseSensitivity)
prefix - the file name prefixcaseSensitivity - how to handle case sensitivity, null means case-sensitivePrefixFileFilterpublic static IOFileFilter sizeFileFilter(long threshold)
threshold - the file size thresholdSizeFileFilterpublic static IOFileFilter sizeFileFilter(long threshold, boolean acceptLarger)
threshold - the file size thresholdacceptLarger - if true, larger files get accepted, if false, smallerSizeFileFilterpublic static IOFileFilter sizeRangeFileFilter(long minSizeInclusive, long maxSizeInclusive)
minSizeInclusive - the minimum file size (inclusive)maxSizeInclusive - the maximum file size (inclusive)SizeFileFilterpublic static IOFileFilter suffixFileFilter(String suffix)
suffix - the file name suffixSuffixFileFilterpublic static IOFileFilter suffixFileFilter(String suffix, IOCase caseSensitivity)
suffix - the file name suffixcaseSensitivity - how to handle case sensitivity, null means case-sensitiveSuffixFileFilterpublic static List<IOFileFilter> toList(IOFileFilter... filters)
filters - The file filtersIllegalArgumentException - if the filters are null or contain a
null value.public static IOFileFilter trueFileFilter()
TrueFileFilter.TRUECopyright © 2002–2021 The Apache Software Foundation. All rights reserved.