public class FileFilterUtils
extends java.lang.Object
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 before
or at 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 before
or at the same time as 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 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(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. |
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.
|
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.public static IOFileFilter prefixFileFilter(java.lang.String prefix)
prefix
- the filename prefixPrefixFileFilter
public static IOFileFilter prefixFileFilter(java.lang.String prefix, IOCase caseSensitivity)
prefix
- the filename prefixcaseSensitivity
- how to handle case sensitivity, null means case-sensitivePrefixFileFilter
public static IOFileFilter suffixFileFilter(java.lang.String suffix)
suffix
- the filename suffixSuffixFileFilter
public static IOFileFilter suffixFileFilter(java.lang.String suffix, IOCase caseSensitivity)
suffix
- the filename suffixcaseSensitivity
- how to handle case sensitivity, null means case-sensitiveSuffixFileFilter
public static IOFileFilter nameFileFilter(java.lang.String name)
name
- the filenameNameFileFilter
public static IOFileFilter nameFileFilter(java.lang.String name, IOCase caseSensitivity)
name
- the filenamecaseSensitivity
- how to handle case sensitivity, null means case-sensitiveNameFileFilter
public static IOFileFilter directoryFileFilter()
DirectoryFileFilter.DIRECTORY
public 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...)
,
OrFileFilter
public 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.AndFileFilter
public 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.OrFileFilter
public 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 invertNotFileFilter
public static IOFileFilter trueFileFilter()
TrueFileFilter.TRUE
public static IOFileFilter falseFileFilter()
FalseFileFilter.FALSE
public static IOFileFilter asFileFilter(java.io.FileFilter filter)
IOFileFilter
that wraps the
FileFilter
instance.filter
- the filter to be wrappedDelegateFileFilter
public static IOFileFilter asFileFilter(java.io.FilenameFilter filter)
IOFileFilter
that wraps the
FilenameFilter
instance.filter
- the filter to be wrappedDelegateFileFilter
public static IOFileFilter ageFileFilter(long cutoff)
cutoff
- the time thresholdAgeFileFilter
public static IOFileFilter ageFileFilter(long cutoff, boolean acceptOlder)
cutoff
- the time thresholdacceptOlder
- if true, older files get accepted, if false, newerAgeFileFilter
public static IOFileFilter ageFileFilter(java.util.Date cutoffDate)
cutoffDate
- the time thresholdAgeFileFilter
public static IOFileFilter ageFileFilter(java.util.Date cutoffDate, boolean acceptOlder)
cutoffDate
- the time thresholdacceptOlder
- if true, older files get accepted, if false, newerAgeFileFilter
public static IOFileFilter ageFileFilter(java.io.File cutoffReference)
cutoffReference
- the file whose last modification
time is used as the threshold age of the filesAgeFileFilter
public static IOFileFilter ageFileFilter(java.io.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, newerAgeFileFilter
public static IOFileFilter sizeFileFilter(long threshold)
threshold
- the file size thresholdSizeFileFilter
public static IOFileFilter sizeFileFilter(long threshold, boolean acceptLarger)
threshold
- the file size thresholdacceptLarger
- if true, larger files get accepted, if false, smallerSizeFileFilter
public static IOFileFilter sizeRangeFileFilter(long minSizeInclusive, long maxSizeInclusive)
minSizeInclusive
- the minimum file size (inclusive)maxSizeInclusive
- the maximum file size (inclusive)SizeFileFilter
public 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.MagicNumberFileFilter
public 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.MagicNumberFileFilter
public 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.MagicNumberFileFilter
public 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.MagicNumberFileFilter
public 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.DIRECTORY
public static IOFileFilter makeFileOnly(IOFileFilter filter)
filter
- the filter to decorate, null means an unrestricted filterFileFileFilter.FILE
Copyright © 2010 - 2020 Adobe. All Rights Reserved