org.apache.commons.io.filefilter

Class FileFilterUtils

public class FileFilterUtils extends Object

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.

Since: Commons IO 1.0

Version: $Id: FileFilterUtils.java 609286 2008-01-06 10:01:26Z scolebourne $

Author: Stephen Colebourne Jeremias Maerki Masato Tezuka Rahul Akolkar

Field Summary
static IOFileFiltercvsFilter
static IOFileFiltersvnFilter
Constructor Summary
FileFilterUtils()
FileFilterUtils is not normally instantiated.
Method Summary
static IOFileFilterageFileFilter(long cutoff)
Returns a filter that returns true if the file was last modified after the specified cutoff time.
static IOFileFilterageFileFilter(long cutoff, boolean acceptOlder)
Returns a filter that filters files based on a cutoff time.
static IOFileFilterageFileFilter(Date cutoffDate)
Returns a filter that returns true if the file was last modified after the specified cutoff date.
static IOFileFilterageFileFilter(Date cutoffDate, boolean acceptOlder)
Returns a filter that filters files based on a cutoff date.
static IOFileFilterageFileFilter(File cutoffReference)
Returns a filter that returns true if the file was last modified after the specified reference file.
static IOFileFilterageFileFilter(File cutoffReference, boolean acceptOlder)
Returns a filter that filters files based on a cutoff reference file.
static IOFileFilterandFileFilter(IOFileFilter filter1, IOFileFilter filter2)
Returns a filter that ANDs the two specified filters.
static IOFileFilterasFileFilter(FileFilter filter)
Returns an IOFileFilter that wraps the FileFilter instance.
static IOFileFilterasFileFilter(FilenameFilter filter)
Returns an IOFileFilter that wraps the FilenameFilter instance.
static IOFileFilterdirectoryFileFilter()
Returns a filter that checks if the file is a directory.
static IOFileFilterfalseFileFilter()
Returns a filter that always returns false.
static IOFileFilterfileFileFilter()
Returns a filter that checks if the file is a file (and not a directory).
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 filename matches the specified text.
static IOFileFilternotFileFilter(IOFileFilter filter)
Returns a filter that NOTs the specified filter.
static IOFileFilterorFileFilter(IOFileFilter filter1, IOFileFilter filter2)
Returns a filter that ORs the two specified filters.
static IOFileFilterprefixFileFilter(String prefix)
Returns a filter that returns true if the filename 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 filename ends with the specified text.
static IOFileFiltertrueFileFilter()
Returns a filter that always returns true.

Field Detail

cvsFilter

private static IOFileFilter cvsFilter

svnFilter

private static IOFileFilter svnFilter

Constructor Detail

FileFilterUtils

public FileFilterUtils()
FileFilterUtils is not normally instantiated.

Method Detail

ageFileFilter

public static IOFileFilter ageFileFilter(long cutoff)
Returns a filter that returns true if the file was last modified after the specified cutoff time.

Parameters: cutoff the time threshold

Returns: an appropriately configured age file filter

Since: Commons IO 1.2

ageFileFilter

public static IOFileFilter ageFileFilter(long cutoff, boolean acceptOlder)
Returns a filter that filters files based on a cutoff time.

Parameters: cutoff the time threshold acceptOlder if true, older files get accepted, if false, newer

Returns: an appropriately configured age file filter

Since: Commons IO 1.2

ageFileFilter

public static IOFileFilter ageFileFilter(Date cutoffDate)
Returns a filter that returns true if the file was last modified after the specified cutoff date.

Parameters: cutoffDate the time threshold

Returns: an appropriately configured age file filter

Since: Commons IO 1.2

ageFileFilter

public static IOFileFilter ageFileFilter(Date cutoffDate, boolean acceptOlder)
Returns 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: Commons IO 1.2

ageFileFilter

public static IOFileFilter ageFileFilter(File cutoffReference)
Returns a filter that returns true if the file was last modified after the specified reference file.

Parameters: cutoffReference the file whose last modification time is usesd as the threshold age of the files

Returns: an appropriately configured age file filter

Since: Commons IO 1.2

ageFileFilter

public static IOFileFilter ageFileFilter(File cutoffReference, boolean acceptOlder)
Returns a filter that filters files based on a cutoff reference file.

Parameters: cutoffReference the file whose last modification time is usesd 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: Commons IO 1.2

andFileFilter

public static IOFileFilter andFileFilter(IOFileFilter filter1, IOFileFilter filter2)
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

asFileFilter

public static IOFileFilter asFileFilter(FileFilter filter)
Returns an IOFileFilter that wraps the FileFilter instance.

Parameters: filter the filter to be wrapped

Returns: a new filter that implements IOFileFilter

asFileFilter

public static IOFileFilter asFileFilter(FilenameFilter filter)
Returns an IOFileFilter that wraps the FilenameFilter instance.

Parameters: filter the filter to be wrapped

Returns: a new filter that implements IOFileFilter

directoryFileFilter

public static IOFileFilter directoryFileFilter()
Returns a filter that checks if the file is a directory.

Returns: file filter that accepts only directories and not files

falseFileFilter

public static IOFileFilter falseFileFilter()
Returns a filter that always returns false.

Returns: a false filter

fileFileFilter

public static IOFileFilter fileFileFilter()
Returns a filter that checks if the file is a file (and not a directory).

Returns: file filter that accepts only files and not directories

makeCVSAware

public static IOFileFilter makeCVSAware(IOFileFilter filter)
Decorates a filter to make it ignore CVS directories. Passing in null will 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: Commons IO 1.1 (method existed but had bug in 1.0)

makeDirectoryOnly

public static IOFileFilter makeDirectoryOnly(IOFileFilter filter)
Decorates 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: Commons IO 1.3

makeFileOnly

public static IOFileFilter makeFileOnly(IOFileFilter filter)
Decorates 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: Commons IO 1.3

makeSVNAware

public static IOFileFilter makeSVNAware(IOFileFilter filter)
Decorates a filter to make it ignore SVN directories. Passing in null will 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: Commons IO 1.1

nameFileFilter

public static IOFileFilter nameFileFilter(String name)
Returns a filter that returns true if the filename matches the specified text.

Parameters: name the filename

Returns: a name checking filter

notFileFilter

public static IOFileFilter notFileFilter(IOFileFilter filter)
Returns a filter that NOTs the specified filter.

Parameters: filter the filter to invert

Returns: a filter that NOTs the specified filter

orFileFilter

public static IOFileFilter orFileFilter(IOFileFilter filter1, IOFileFilter filter2)
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

prefixFileFilter

public static IOFileFilter prefixFileFilter(String prefix)
Returns a filter that returns true if the filename starts with the specified text.

Parameters: prefix the filename prefix

Returns: a prefix checking filter

sizeFileFilter

public static IOFileFilter sizeFileFilter(long threshold)
Returns 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: Commons IO 1.2

sizeFileFilter

public static IOFileFilter sizeFileFilter(long threshold, boolean acceptLarger)
Returns 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: Commons IO 1.2

sizeRangeFileFilter

public static IOFileFilter sizeRangeFileFilter(long minSizeInclusive, long maxSizeInclusive)
Returns 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: Commons IO 1.3

suffixFileFilter

public static IOFileFilter suffixFileFilter(String suffix)
Returns a filter that returns true if the filename ends with the specified text.

Parameters: suffix the filename suffix

Returns: a suffix checking filter

trueFileFilter

public static IOFileFilter trueFileFilter()
Returns a filter that always returns true.

Returns: a true filter

Copyright (c) 2002-2011 Apache Software Foundation