public class FileFilterUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private static IOFileFilter |
cvsFilter |
private static IOFileFilter |
svnFilter |
| Constructor and Description |
|---|
FileFilterUtils()
FileFilterUtils is not normally instantiated.
|
| Modifier and Type | Method and Description |
|---|---|
static IOFileFilter |
ageFileFilter(java.util.Date cutoffDate)
Returns a filter that returns true if the file was last modified after
the specified cutoff date.
|
static IOFileFilter |
ageFileFilter(java.util.Date cutoffDate,
boolean acceptOlder)
Returns a filter that filters files based on a cutoff date.
|
static IOFileFilter |
ageFileFilter(java.io.File cutoffReference)
Returns a filter that returns true if the file was last modified after
the specified reference file.
|
static IOFileFilter |
ageFileFilter(java.io.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 after
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(java.io.FileFilter filter)
Returns an
IOFileFilter that wraps the
FileFilter instance. |
static IOFileFilter |
asFileFilter(java.io.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 java.io.File[] |
filter(IOFileFilter filter,
java.io.File... files)
Applies an
IOFileFilter to the provided File
objects. |
static java.io.File[] |
filter(IOFileFilter filter,
java.lang.Iterable<java.io.File> files)
Applies an
IOFileFilter to the provided File
objects. |
private static <T extends java.util.Collection<java.io.File>> |
filter(IOFileFilter filter,
java.lang.Iterable<java.io.File> files,
T acceptedFiles)
Applies an
IOFileFilter to the provided File
objects and appends the accepted files to the other supplied collection. |
static java.util.List<java.io.File> |
filterList(IOFileFilter filter,
java.io.File... files)
Applies an
IOFileFilter to the provided File
objects. |
static java.util.List<java.io.File> |
filterList(IOFileFilter filter,
java.lang.Iterable<java.io.File> files)
Applies an
IOFileFilter to the provided File
objects. |
static java.util.Set<java.io.File> |
filterSet(IOFileFilter filter,
java.io.File... files)
Applies an
IOFileFilter to the provided File
objects. |
static java.util.Set<java.io.File> |
filterSet(IOFileFilter filter,
java.lang.Iterable<java.io.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(java.lang.String magicNumber)
Returns a filter that accepts files that begin with the provided magic
number.
|
static IOFileFilter |
magicNumberFileFilter(java.lang.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(java.lang.String name)
Returns a filter that returns true if the filename matches the specified text.
|
static IOFileFilter |
nameFileFilter(java.lang.String name,
IOCase caseSensitivity)
Returns a filter that returns true if the filename 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(java.lang.String prefix)
Returns a filter that returns true if the filename starts with the specified text.
|
static IOFileFilter |
prefixFileFilter(java.lang.String prefix,
IOCase caseSensitivity)
Returns a filter that returns true if the filename 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(java.lang.String suffix)
Returns a filter that returns true if the filename ends with the specified text.
|
static IOFileFilter |
suffixFileFilter(java.lang.String suffix,
IOCase caseSensitivity)
Returns a filter that returns true if the filename ends with the specified text.
|
static java.util.List<IOFileFilter> |
toList(IOFileFilter... filters)
Create a List of file filters.
|
static IOFileFilter |
trueFileFilter()
Returns a filter that always returns true.
|
private static final IOFileFilter cvsFilter
private static final IOFileFilter svnFilter
public FileFilterUtils()
public static java.io.File[] filter(IOFileFilter filter, java.io.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.java.lang.IllegalArgumentException - if the filter is null
or files contains a null value.public static java.io.File[] filter(IOFileFilter filter, java.lang.Iterable<java.io.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.java.lang.IllegalArgumentException - if the filter is null
or files contains a null value.public static java.util.List<java.io.File> filterList(IOFileFilter filter, java.lang.Iterable<java.io.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.java.lang.IllegalArgumentException - if the filter is null
or files contains a null value.public static java.util.List<java.io.File> filterList(IOFileFilter filter, java.io.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.java.lang.IllegalArgumentException - if the filter is null
or files contains a null value.public static java.util.Set<java.io.File> filterSet(IOFileFilter filter, java.io.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.java.lang.IllegalArgumentException - if the filter is null
or files contains a null value.public static java.util.Set<java.io.File> filterSet(IOFileFilter filter, java.lang.Iterable<java.io.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.java.lang.IllegalArgumentException - if the filter is null
or files contains a null value.private static <T extends java.util.Collection<java.io.File>> T filter(IOFileFilter filter, java.lang.Iterable<java.io.File> files, T acceptedFiles)
Applies an IOFileFilter to the provided File
objects and appends the accepted files to the other supplied collection.
List<File> files = ...
List<File> directories = FileFilterUtils.filterList(files,
FileFilterUtils.sizeFileFilter(FileUtils.FIFTY_MB),
new ArrayList<File>());
T - the type of the file collection.filter - the filter to apply to the collection of files.files - the collection of files to apply the filter to.acceptedFiles - the list of files to add accepted files to.files that is accepted by the
file filter.java.lang.IllegalArgumentException - if the filter is null
or files contains a null value.public static IOFileFilter prefixFileFilter(java.lang.String prefix)
prefix - the filename prefixPrefixFileFilterpublic static IOFileFilter prefixFileFilter(java.lang.String prefix, IOCase caseSensitivity)
prefix - the filename prefixcaseSensitivity - how to handle case sensitivity, null means case-sensitivePrefixFileFilterpublic static IOFileFilter suffixFileFilter(java.lang.String suffix)
suffix - the filename suffixSuffixFileFilterpublic static IOFileFilter suffixFileFilter(java.lang.String suffix, IOCase caseSensitivity)
suffix - the filename suffixcaseSensitivity - how to handle case sensitivity, null means case-sensitiveSuffixFileFilterpublic static IOFileFilter nameFileFilter(java.lang.String name)
name - the filenameNameFileFilterpublic static IOFileFilter nameFileFilter(java.lang.String name, IOCase caseSensitivity)
name - the filenamecaseSensitivity - how to handle case sensitivity, null means case-sensitiveNameFileFilterpublic static IOFileFilter directoryFileFilter()
DirectoryFileFilter.DIRECTORYpublic static IOFileFilter fileFileFilter()
FileFileFilter.FILE@Deprecated public static IOFileFilter andFileFilter(IOFileFilter filter1, IOFileFilter filter2)
and(IOFileFilter...)filter1 - the first filterfilter2 - the second filterand(IOFileFilter...),
AndFileFilter@Deprecated public static IOFileFilter orFileFilter(IOFileFilter filter1, IOFileFilter filter2)
or(IOFileFilter...)filter1 - the first filterfilter2 - the second filteror(IOFileFilter...),
OrFileFilterpublic static IOFileFilter and(IOFileFilter... filters)
filters - the IOFileFilters that will be ANDed together.java.lang.IllegalArgumentException - if the filters are null or contain a
null value.AndFileFilterpublic static IOFileFilter or(IOFileFilter... filters)
filters - the IOFileFilters that will be ORed together.java.lang.IllegalArgumentException - if the filters are null or contain a
null value.OrFileFilterpublic static java.util.List<IOFileFilter> toList(IOFileFilter... filters)
filters - The file filtersjava.lang.IllegalArgumentException - if the filters are null or contain a
null value.public static IOFileFilter notFileFilter(IOFileFilter filter)
filter - the filter to invertNotFileFilterpublic static IOFileFilter trueFileFilter()
TrueFileFilter.TRUEpublic static IOFileFilter falseFileFilter()
FalseFileFilter.FALSEpublic static IOFileFilter asFileFilter(java.io.FileFilter filter)
IOFileFilter that wraps the
FileFilter instance.filter - the filter to be wrappedDelegateFileFilterpublic static IOFileFilter asFileFilter(java.io.FilenameFilter filter)
IOFileFilter that wraps the
FilenameFilter instance.filter - the filter to be wrappedDelegateFileFilterpublic 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 ageFileFilter(java.util.Date cutoffDate)
cutoffDate - the time thresholdAgeFileFilterpublic static IOFileFilter ageFileFilter(java.util.Date cutoffDate, boolean acceptOlder)
cutoffDate - the time thresholdacceptOlder - if true, older files get accepted, if false, newerAgeFileFilterpublic static IOFileFilter ageFileFilter(java.io.File cutoffReference)
cutoffReference - the file whose last modification
time is usesd as the threshold age of the filesAgeFileFilterpublic static IOFileFilter ageFileFilter(java.io.File cutoffReference, boolean acceptOlder)
cutoffReference - the file whose last modification
time is usesd as the threshold age of the filesacceptOlder - if true, older files get accepted, if false, newerAgeFileFilterpublic 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 magicNumberFileFilter(java.lang.String magicNumber)
magicNumber - the magic number (byte sequence) to match at the
beginning of each file.java.lang.IllegalArgumentException - if magicNumber is
null or the empty String.MagicNumberFileFilterpublic static IOFileFilter magicNumberFileFilter(java.lang.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.java.lang.IllegalArgumentException - if magicNumber is
null or the empty String, or if offset is a
negative number.MagicNumberFileFilterpublic static IOFileFilter magicNumberFileFilter(byte[] magicNumber)
magicNumber - the magic number (byte sequence) to match at the
beginning of each file.java.lang.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.java.lang.IllegalArgumentException - if magicNumber is
null, or contains no bytes, or 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 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 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.FILECopyright (c) 2002-2016 Apache Software Foundation