FileDocCategorySizeDatePackage
FileFilterUtils.javaAPI DocAndroid 1.5 API12923Wed May 06 22:42:46 BST 2009org.apache.commons.io.filefilter

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
author
Jeremias Maerki
author
Masato Tezuka
author
Rahul Akolkar

Fields Summary
private static IOFileFilter
cvsFilter
private static IOFileFilter
svnFilter
Constructors Summary
public FileFilterUtils()
FileFilterUtils is not normally instantiated.

    
Methods Summary
public static org.apache.commons.io.filefilter.IOFileFilterageFileFilter(long cutoff)
Returns a filter that returns true if the file was last modified after the specified cutoff time.

param
cutoff the time threshold
return
an appropriately configured age file filter
since
Commons IO 1.2

        return new AgeFileFilter(cutoff);
    
public static org.apache.commons.io.filefilter.IOFileFilterageFileFilter(long cutoff, boolean acceptOlder)
Returns a filter that filters files based on a cutoff time.

param
cutoff the time threshold
param
acceptOlder if true, older files get accepted, if false, newer
return
an appropriately configured age file filter
since
Commons IO 1.2

        return new AgeFileFilter(cutoff, acceptOlder);
    
public static org.apache.commons.io.filefilter.IOFileFilterageFileFilter(java.util.Date cutoffDate)
Returns a filter that returns true if the file was last modified after the specified cutoff date.

param
cutoffDate the time threshold
return
an appropriately configured age file filter
since
Commons IO 1.2

        return new AgeFileFilter(cutoffDate);
    
public static org.apache.commons.io.filefilter.IOFileFilterageFileFilter(java.util.Date cutoffDate, boolean acceptOlder)
Returns a filter that filters files based on a cutoff date.

param
cutoffDate the time threshold
param
acceptOlder if true, older files get accepted, if false, newer
return
an appropriately configured age file filter
since
Commons IO 1.2

        return new AgeFileFilter(cutoffDate, acceptOlder);
    
public static org.apache.commons.io.filefilter.IOFileFilterageFileFilter(java.io.File cutoffReference)
Returns a filter that returns true if the file was last modified after the specified reference file.

param
cutoffReference the file whose last modification time is usesd as the threshold age of the files
return
an appropriately configured age file filter
since
Commons IO 1.2

        return new AgeFileFilter(cutoffReference);
    
public static org.apache.commons.io.filefilter.IOFileFilterageFileFilter(java.io.File cutoffReference, boolean acceptOlder)
Returns a filter that filters files based on a cutoff reference file.

param
cutoffReference the file whose last modification time is usesd as the threshold age of the files
param
acceptOlder if true, older files get accepted, if false, newer
return
an appropriately configured age file filter
since
Commons IO 1.2

        return new AgeFileFilter(cutoffReference, acceptOlder);
    
public static org.apache.commons.io.filefilter.IOFileFilterandFileFilter(org.apache.commons.io.filefilter.IOFileFilter filter1, org.apache.commons.io.filefilter.IOFileFilter filter2)
Returns a filter that ANDs the two specified filters.

param
filter1 the first filter
param
filter2 the second filter
return
a filter that ANDs the two specified filters

        return new AndFileFilter(filter1, filter2);
    
public static org.apache.commons.io.filefilter.IOFileFilterasFileFilter(java.io.FileFilter filter)
Returns an IOFileFilter that wraps the FileFilter instance.

param
filter the filter to be wrapped
return
a new filter that implements IOFileFilter

        return new DelegateFileFilter(filter);
    
public static org.apache.commons.io.filefilter.IOFileFilterasFileFilter(java.io.FilenameFilter filter)
Returns an IOFileFilter that wraps the FilenameFilter instance.

param
filter the filter to be wrapped
return
a new filter that implements IOFileFilter

        return new DelegateFileFilter(filter);
    
public static org.apache.commons.io.filefilter.IOFileFilterdirectoryFileFilter()
Returns a filter that checks if the file is a directory.

return
file filter that accepts only directories and not files

        return DirectoryFileFilter.DIRECTORY;
    
public static org.apache.commons.io.filefilter.IOFileFilterfalseFileFilter()
Returns a filter that always returns false.

return
a false filter

        return FalseFileFilter.FALSE;
    
public static org.apache.commons.io.filefilter.IOFileFilterfileFileFilter()
Returns a filter that checks if the file is a file (and not a directory).

return
file filter that accepts only files and not directories

        return FileFileFilter.FILE;
    
public static org.apache.commons.io.filefilter.IOFileFiltermakeCVSAware(org.apache.commons.io.filefilter.IOFileFilter filter)
Decorates a filter to make it ignore CVS directories. Passing in null will return a filter that accepts everything except CVS directories.

param
filter the filter to decorate, null means an unrestricted filter
return
the decorated filter, never null
since
Commons IO 1.1 (method existed but had bug in 1.0)

        if (cvsFilter == null) {
            cvsFilter = notFileFilter(
                andFileFilter(directoryFileFilter(), nameFileFilter("CVS")));
        }
        if (filter == null) {
            return cvsFilter;
        } else {
            return andFileFilter(filter, cvsFilter);
        }
    
public static org.apache.commons.io.filefilter.IOFileFiltermakeDirectoryOnly(org.apache.commons.io.filefilter.IOFileFilter filter)
Decorates a filter so that it only applies to directories and not to files.

param
filter the filter to decorate, null means an unrestricted filter
return
the decorated filter, never null
since
Commons IO 1.3

        if (filter == null) {
            return DirectoryFileFilter.DIRECTORY;
        }
        return new AndFileFilter(DirectoryFileFilter.DIRECTORY, filter);
    
public static org.apache.commons.io.filefilter.IOFileFiltermakeFileOnly(org.apache.commons.io.filefilter.IOFileFilter filter)
Decorates a filter so that it only applies to files and not to directories.

param
filter the filter to decorate, null means an unrestricted filter
return
the decorated filter, never null
since
Commons IO 1.3

        if (filter == null) {
            return FileFileFilter.FILE;
        }
        return new AndFileFilter(FileFileFilter.FILE, filter);
    
public static org.apache.commons.io.filefilter.IOFileFiltermakeSVNAware(org.apache.commons.io.filefilter.IOFileFilter filter)
Decorates a filter to make it ignore SVN directories. Passing in null will return a filter that accepts everything except SVN directories.

param
filter the filter to decorate, null means an unrestricted filter
return
the decorated filter, never null
since
Commons IO 1.1

        if (svnFilter == null) {
            svnFilter = notFileFilter(
                andFileFilter(directoryFileFilter(), nameFileFilter(".svn")));
        }
        if (filter == null) {
            return svnFilter;
        } else {
            return andFileFilter(filter, svnFilter);
        }
    
public static org.apache.commons.io.filefilter.IOFileFilternameFileFilter(java.lang.String name)
Returns a filter that returns true if the filename matches the specified text.

param
name the filename
return
a name checking filter

        return new NameFileFilter(name);
    
public static org.apache.commons.io.filefilter.IOFileFilternotFileFilter(org.apache.commons.io.filefilter.IOFileFilter filter)
Returns a filter that NOTs the specified filter.

param
filter the filter to invert
return
a filter that NOTs the specified filter

        return new NotFileFilter(filter);
    
public static org.apache.commons.io.filefilter.IOFileFilterorFileFilter(org.apache.commons.io.filefilter.IOFileFilter filter1, org.apache.commons.io.filefilter.IOFileFilter filter2)
Returns a filter that ORs the two specified filters.

param
filter1 the first filter
param
filter2 the second filter
return
a filter that ORs the two specified filters

        return new OrFileFilter(filter1, filter2);
    
public static org.apache.commons.io.filefilter.IOFileFilterprefixFileFilter(java.lang.String prefix)
Returns a filter that returns true if the filename starts with the specified text.

param
prefix the filename prefix
return
a prefix checking filter

        return new PrefixFileFilter(prefix);
    
public static org.apache.commons.io.filefilter.IOFileFiltersizeFileFilter(long threshold)
Returns a filter that returns true if the file is bigger than a certain size.

param
threshold the file size threshold
return
an appropriately configured SizeFileFilter
since
Commons IO 1.2

        return new SizeFileFilter(threshold);
    
public static org.apache.commons.io.filefilter.IOFileFiltersizeFileFilter(long threshold, boolean acceptLarger)
Returns a filter that filters based on file size.

param
threshold the file size threshold
param
acceptLarger if true, larger files get accepted, if false, smaller
return
an appropriately configured SizeFileFilter
since
Commons IO 1.2

        return new SizeFileFilter(threshold, acceptLarger);
    
public static org.apache.commons.io.filefilter.IOFileFiltersizeRangeFileFilter(long minSizeInclusive, long maxSizeInclusive)
Returns a filter that accepts files whose size is >= minimum size and <= maximum size.

param
minSizeInclusive the minimum file size (inclusive)
param
maxSizeInclusive the maximum file size (inclusive)
return
an appropriately configured IOFileFilter
since
Commons IO 1.3

        IOFileFilter minimumFilter = new SizeFileFilter(minSizeInclusive, true);
        IOFileFilter maximumFilter = new SizeFileFilter(maxSizeInclusive + 1L, false);
        return new AndFileFilter(minimumFilter, maximumFilter);
    
public static org.apache.commons.io.filefilter.IOFileFiltersuffixFileFilter(java.lang.String suffix)
Returns a filter that returns true if the filename ends with the specified text.

param
suffix the filename suffix
return
a suffix checking filter

        return new SuffixFileFilter(suffix);
    
public static org.apache.commons.io.filefilter.IOFileFiltertrueFileFilter()
Returns a filter that always returns true.

return
a true filter

        return TrueFileFilter.TRUE;