|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.io.filefilter.FileFilterUtils
public class FileFilterUtils
Useful utilities for working with file filters. It provides access to all file filter implementations in this package so you don't have to import every class you use.
Constructor Summary | |
---|---|
FileFilterUtils()
FileFilterUtils is not normally instantiated. |
Method Summary | |
---|---|
static IOFileFilter |
ageFileFilter(Date cutoffDate)
Returns a filter that returns true if the file was last modified after 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 after 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 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. use and(IOFileFilter...) |
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 filename matches the specified text. |
static IOFileFilter |
nameFileFilter(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. use or(IOFileFilter...) |
static IOFileFilter |
prefixFileFilter(String prefix)
Returns a filter that returns true if the filename starts with the specified text. |
static IOFileFilter |
prefixFileFilter(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(String suffix)
Returns a filter that returns true if the filename ends with the specified text. |
static IOFileFilter |
suffixFileFilter(String suffix,
IOCase caseSensitivity)
Returns a filter that returns true if the filename 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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FileFilterUtils()
Method Detail |
---|
public 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.
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 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, 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 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 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 null
or files
contains a null
value.public static IOFileFilter prefixFileFilter(String prefix)
prefix
- the filename prefix
PrefixFileFilter
public static IOFileFilter prefixFileFilter(String prefix, IOCase caseSensitivity)
prefix
- the filename prefixcaseSensitivity
- how to handle case sensitivity, null means case-sensitive
PrefixFileFilter
public static IOFileFilter suffixFileFilter(String suffix)
suffix
- the filename suffix
SuffixFileFilter
public static IOFileFilter suffixFileFilter(String suffix, IOCase caseSensitivity)
suffix
- the filename suffixcaseSensitivity
- how to handle case sensitivity, null means case-sensitive
SuffixFileFilter
public static IOFileFilter nameFileFilter(String name)
name
- the filename
NameFileFilter
public static IOFileFilter nameFileFilter(String name, IOCase caseSensitivity)
name
- the filenamecaseSensitivity
- how to handle case sensitivity, null means case-sensitive
NameFileFilter
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 filter
and(IOFileFilter...)
,
AndFileFilter
@Deprecated public static IOFileFilter orFileFilter(IOFileFilter filter1, IOFileFilter filter2)
or(IOFileFilter...)
filter1
- the first filterfilter2
- the second filter
or(IOFileFilter...)
,
OrFileFilter
public 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
public 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
public static List<IOFileFilter> toList(IOFileFilter... filters)
filters
- The file filters
IllegalArgumentException
- if the filters are null or contain a
null value.public static IOFileFilter notFileFilter(IOFileFilter filter)
filter
- the filter to invert
NotFileFilter
public static IOFileFilter trueFileFilter()
TrueFileFilter.TRUE
public static IOFileFilter falseFileFilter()
FalseFileFilter.FALSE
public static IOFileFilter asFileFilter(FileFilter filter)
IOFileFilter
that wraps the
FileFilter
instance.
filter
- the filter to be wrapped
DelegateFileFilter
public static IOFileFilter asFileFilter(FilenameFilter filter)
IOFileFilter
that wraps the
FilenameFilter
instance.
filter
- the filter to be wrapped
DelegateFileFilter
public static IOFileFilter ageFileFilter(long cutoff)
cutoff
- the time threshold
AgeFileFilter
public static IOFileFilter ageFileFilter(long cutoff, boolean acceptOlder)
cutoff
- the time thresholdacceptOlder
- if true, older files get accepted, if false, newer
AgeFileFilter
public static IOFileFilter ageFileFilter(Date cutoffDate)
cutoffDate
- the time threshold
AgeFileFilter
public static IOFileFilter ageFileFilter(Date cutoffDate, boolean acceptOlder)
cutoffDate
- the time thresholdacceptOlder
- if true, older files get accepted, if false, newer
AgeFileFilter
public static IOFileFilter ageFileFilter(File cutoffReference)
cutoffReference
- the file whose last modification
time is usesd as the threshold age of the files
AgeFileFilter
public static IOFileFilter ageFileFilter(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, newer
AgeFileFilter
public static IOFileFilter sizeFileFilter(long threshold)
threshold
- the file size threshold
SizeFileFilter
public static IOFileFilter sizeFileFilter(long threshold, boolean acceptLarger)
threshold
- the file size thresholdacceptLarger
- if true, larger files get accepted, if false, smaller
SizeFileFilter
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(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.MagicNumberFileFilter
public 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.MagicNumberFileFilter
public 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.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.
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 filter
public 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 filter
public static IOFileFilter makeDirectoryOnly(IOFileFilter filter)
filter
- the filter to decorate, null means an unrestricted filter
DirectoryFileFilter.DIRECTORY
public static IOFileFilter makeFileOnly(IOFileFilter filter)
filter
- the filter to decorate, null means an unrestricted filter
FileFileFilter.FILE
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |