? FileFilterUtils

java.lang.Object
org.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.
???????:
1.0
  • ???????

    • FileFilterUtils

      public FileFilterUtils()
      FileFilterUtils is not normally instantiated.
  • ??????

    • ageFileFilter

      public static IOFileFilter ageFileFilter(Date cutoffDate)
      Returns a filter that returns true if the file was last modified before or at the specified cutoff date.
      ??:
      cutoffDate - the time threshold
      ??:
      an appropriately configured age file filter
      ???????:
      1.2
      ????:
    • ageFileFilter

      public static IOFileFilter ageFileFilter(Date cutoffDate, boolean acceptOlder)
      Returns a filter that filters files based on a cutoff date.
      ??:
      cutoffDate - the time threshold
      acceptOlder - if true, older files get accepted, if false, newer
      ??:
      an appropriately configured age file filter
      ???????:
      1.2
      ????:
    • ageFileFilter

      public static IOFileFilter ageFileFilter(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.
      ??:
      cutoffReference - the file whose last modification time is used as the threshold age of the files
      ??:
      an appropriately configured age file filter
      ???????:
      1.2
      ????:
    • ageFileFilter

      public static IOFileFilter ageFileFilter(File cutoffReference, boolean acceptOlder)
      Returns a filter that filters files based on a cutoff reference file.
      ??:
      cutoffReference - the file whose last modification time is used as the threshold age of the files
      acceptOlder - if true, older files get accepted, if false, newer
      ??:
      an appropriately configured age file filter
      ???????:
      1.2
      ????:
    • ageFileFilter

      public static IOFileFilter ageFileFilter(long cutoff)
      Returns a filter that returns true if the file was last modified before or at the specified cutoff time.
      ??:
      cutoff - the time threshold
      ??:
      an appropriately configured age file filter
      ???????:
      1.2
      ????:
    • ageFileFilter

      public static IOFileFilter ageFileFilter(long cutoff, boolean acceptOlder)
      Returns a filter that filters files based on a cutoff time.
      ??:
      cutoff - the time threshold
      acceptOlder - if true, older files get accepted, if false, newer
      ??:
      an appropriately configured age file filter
      ???????:
      1.2
      ????:
    • and

      public static IOFileFilter and(IOFileFilter... filters)
      Returns a filter that ANDs the specified filters.
      ??:
      filters - the IOFileFilters that will be ANDed together.
      ??:
      a filter that ANDs the specified filters
      ??:
      IllegalArgumentException - if the filters are null or contain a null value.
      ???????:
      2.0
      ????:
    • andFileFilter

      @Deprecated public static IOFileFilter andFileFilter(IOFileFilter filter1, IOFileFilter filter2)
      Returns a filter that ANDs the two specified filters.
      ??:
      filter1 - the first filter
      filter2 - the second filter
      ??:
      a filter that ANDs the two specified filters
      ????:
    • asFileFilter

      public static IOFileFilter asFileFilter(FileFilter filter)
      Returns an IOFileFilter that wraps the FileFilter instance.
      ??:
      filter - the filter to be wrapped
      ??:
      a new filter that implements IOFileFilter
      ????:
    • asFileFilter

      public static IOFileFilter asFileFilter(FilenameFilter filter)
      Returns an IOFileFilter that wraps the FilenameFilter instance.
      ??:
      filter - the filter to be wrapped
      ??:
      a new filter that implements IOFileFilter
      ????:
    • directoryFileFilter

      Returns a filter that checks if the file is a directory.
      ??:
      file filter that accepts only directories and not files
      ????:
    • falseFileFilter

      public static IOFileFilter falseFileFilter()
      Returns a filter that always returns false.
      ??:
      a false filter
      ????:
    • fileFileFilter

      public static IOFileFilter fileFileFilter()
      Returns a filter that checks if the file is a file (and not a directory).
      ??:
      file filter that accepts only files and not directories
      ????:
    • filter

      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.

       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.
      ??:
      a subset of files that is accepted by the file filter.
      ??:
      IllegalArgumentException - if the filter is null or files contains a null value.
      ???????:
      2.0
    • filter

      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.
      ??:
      a subset of files that is accepted by the file filter.
      ??:
      IllegalArgumentException - if the filter is null or files contains a null value.
      ???????:
      2.0
    • filterList

      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.
      ??:
      a subset of files that is accepted by the file filter.
      ??:
      IllegalArgumentException - if the filter is null or files contains a null value.
      ???????:
      2.0
    • filterList

      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.
      ??:
      a subset of files that is accepted by the file filter.
      ??:
      IllegalArgumentException - if the filter is null
      ???????:
      2.0
    • filterSet

      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.
      ??:
      a subset of files that is accepted by the file filter.
      ??:
      IllegalArgumentException - if the filter is null or files contains a null value.
      ???????:
      2.0
    • filterSet

      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.
      ??:
      a subset of files that is accepted by the file filter.
      ??:
      IllegalArgumentException - if the filter is null
      ???????:
      2.0
    • magicNumberFileFilter

      public static IOFileFilter magicNumberFileFilter(byte[] magicNumber)
      Returns a filter that accepts files that begin with the provided magic number.
      ??:
      magicNumber - the magic number (byte sequence) to match at the beginning of each file.
      ??:
      an IOFileFilter that accepts files beginning with the provided magic number.
      ??:
      IllegalArgumentException - if magicNumber is null or is of length zero.
      ???????:
      2.0
      ????:
    • magicNumberFileFilter

      public 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.
      ??:
      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.
      ??:
      an IOFileFilter that accepts files containing the magic number at the specified offset.
      ??:
      IllegalArgumentException - if magicNumber is null, or contains no bytes, or offset is a negative number.
      ???????:
      2.0
      ????:
    • magicNumberFileFilter

      public static IOFileFilter magicNumberFileFilter(String magicNumber)
      Returns a filter that accepts files that begin with the provided magic number.
      ??:
      magicNumber - the magic number (byte sequence) to match at the beginning of each file.
      ??:
      an IOFileFilter that accepts files beginning with the provided magic number.
      ??:
      IllegalArgumentException - if magicNumber is null or the empty String.
      ???????:
      2.0
      ????:
    • magicNumberFileFilter

      public 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.
      ??:
      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.
      ??:
      an IOFileFilter that accepts files containing the magic number at the specified offset.
      ??:
      IllegalArgumentException - if magicNumber is null or the empty String, or if offset is a negative number.
      ???????:
      2.0
      ????:
    • 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.
      ??:
      filter - the filter to decorate, null means an unrestricted filter
      ??:
      the decorated filter, never null
      ???????:
      1.1 (method existed but had bug in 1.0)
    • makeDirectoryOnly

      Decorates a filter so that it only applies to directories and not to files.
      ??:
      filter - the filter to decorate, null means an unrestricted filter
      ??:
      the decorated filter, never null
      ???????:
      1.3
      ????:
    • makeFileOnly

      public static IOFileFilter makeFileOnly(IOFileFilter filter)
      Decorates a filter so that it only applies to files and not to directories.
      ??:
      filter - the filter to decorate, null means an unrestricted filter
      ??:
      the decorated filter, never null
      ???????:
      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.
      ??:
      filter - the filter to decorate, null means an unrestricted filter
      ??:
      the decorated filter, never null
      ???????:
      1.1
    • nameFileFilter

      public static IOFileFilter nameFileFilter(String name)
      Returns a filter that returns true if the file name matches the specified text.
      ??:
      name - the file name
      ??:
      a name checking filter
      ????:
    • nameFileFilter

      public static IOFileFilter nameFileFilter(String name, IOCase caseSensitivity)
      Returns a filter that returns true if the file name matches the specified text.
      ??:
      name - the file name
      caseSensitivity - how to handle case sensitivity, null means case-sensitive
      ??:
      a name checking filter
      ???????:
      2.0
      ????:
    • notFileFilter

      public static IOFileFilter notFileFilter(IOFileFilter filter)
      Returns a filter that NOTs the specified filter.
      ??:
      filter - the filter to invert
      ??:
      a filter that NOTs the specified filter
      ????:
    • or

      public static IOFileFilter or(IOFileFilter... filters)
      Returns a filter that ORs the specified filters.
      ??:
      filters - the IOFileFilters that will be ORed together.
      ??:
      a filter that ORs the specified filters
      ??:
      IllegalArgumentException - if the filters are null or contain a null value.
      ???????:
      2.0
      ????:
    • orFileFilter

      @Deprecated public static IOFileFilter orFileFilter(IOFileFilter filter1, IOFileFilter filter2)
      Returns a filter that ORs the two specified filters.
      ??:
      filter1 - the first filter
      filter2 - the second filter
      ??:
      a filter that ORs the two specified filters
      ????:
    • prefixFileFilter

      public static IOFileFilter prefixFileFilter(String prefix)
      Returns a filter that returns true if the file name starts with the specified text.
      ??:
      prefix - the file name prefix
      ??:
      a prefix checking filter
      ????:
    • prefixFileFilter

      public static IOFileFilter prefixFileFilter(String prefix, IOCase caseSensitivity)
      Returns a filter that returns true if the file name starts with the specified text.
      ??:
      prefix - the file name prefix
      caseSensitivity - how to handle case sensitivity, null means case-sensitive
      ??:
      a prefix checking filter
      ???????:
      2.0
      ????:
    • sizeFileFilter

      public static IOFileFilter sizeFileFilter(long threshold)
      Returns a filter that returns true if the file is bigger than a certain size.
      ??:
      threshold - the file size threshold
      ??:
      an appropriately configured SizeFileFilter
      ???????:
      1.2
      ????:
    • sizeFileFilter

      public static IOFileFilter sizeFileFilter(long threshold, boolean acceptLarger)
      Returns a filter that filters based on file size.
      ??:
      threshold - the file size threshold
      acceptLarger - if true, larger files get accepted, if false, smaller
      ??:
      an appropriately configured SizeFileFilter
      ???????:
      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.
      ??:
      minSizeInclusive - the minimum file size (inclusive)
      maxSizeInclusive - the maximum file size (inclusive)
      ??:
      an appropriately configured IOFileFilter
      ???????:
      1.3
      ????:
    • suffixFileFilter

      public static IOFileFilter suffixFileFilter(String suffix)
      Returns a filter that returns true if the file name ends with the specified text.
      ??:
      suffix - the file name suffix
      ??:
      a suffix checking filter
      ????:
    • suffixFileFilter

      public static IOFileFilter suffixFileFilter(String suffix, IOCase caseSensitivity)
      Returns a filter that returns true if the file name ends with the specified text.
      ??:
      suffix - the file name suffix
      caseSensitivity - how to handle case sensitivity, null means case-sensitive
      ??:
      a suffix checking filter
      ???????:
      2.0
      ????:
    • toList

      public static List<IOFileFilter> toList(IOFileFilter... filters)
      Create a List of file filters.
      ??:
      filters - The file filters
      ??:
      The list of file filters
      ??:
      IllegalArgumentException - if the filters are null or contain a null value.
      ???????:
      2.0
    • trueFileFilter

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