Class SuffixFileFilter

java.lang.Object
org.apache.commons.vfs2.filter.SuffixFileFilter
All Implemented Interfaces:
Serializable, FileFilter

public class SuffixFileFilter extends Object implements FileFilter, Serializable
Filters files based on the suffix (what the file name ends with). This is used in retrieving all the files of a particular type.

For example, to retrieve and print all *.java files in the current directory:

 FileSystemManager fsManager = VFS.getManager();
 FileObject dir = fsManager.toFileObject(new File("."));
 FileObject[] files = dir.findFiles(new FileFilterSelector(new SuffixFileFilter(".java")));
 for (int i = 0; i < files.length; i++) {
     System.out.println(files[i]);
 }
 
Since:
2.4
Author:
This code was originally ported from Apache Commons IO File Filter
See Also:
  • Constructor Details Link icon

    • SuffixFileFilter Link icon

      public SuffixFileFilter(IOCase caseSensitivity, List<String> suffixes)
      Constructs a new Suffix file filter for a list of suffixes specifying case-sensitivity.
      Parameters:
      caseSensitivity - how to handle case sensitivity, null means case-sensitive
      suffixes - the suffixes to allow, must not be null
    • SuffixFileFilter Link icon

      public SuffixFileFilter(IOCase caseSensitivity, String... suffixes)
      Constructs a new Suffix file filter for an array of suffixes specifying case-sensitivity.
      Parameters:
      caseSensitivity - how to handle case sensitivity, null means case-sensitive
      suffixes - the suffixes to allow, must not be null
    • SuffixFileFilter Link icon

      public SuffixFileFilter(List<String> suffixes)
      Constructs a new Suffix file filter for a list of suffixes.
      Parameters:
      suffixes - the suffixes to allow, must not be null
    • SuffixFileFilter Link icon

      public SuffixFileFilter(String... suffixes)
      Constructs a new Suffix file filter for an array of suffixes.
      Parameters:
      suffixes - the suffixes to allow, must not be null
  • Method Details Link icon

    • accept Link icon

      public boolean accept(FileSelectInfo fileSelectInfo)
      Checks to see if the file name ends with the suffix.
      Specified by:
      accept in interface FileFilter
      Parameters:
      fileSelectInfo - the File to check
      Returns:
      true if the file name ends with one of our suffixes
    • toString Link icon

      public String toString()
      Provides a String representation of this file filter.
      Overrides:
      toString in class Object
      Returns:
      a String representation