Package org.apache.commons.vfs2.filter
Class SuffixFileFilter
- java.lang.Object
-
- org.apache.commons.vfs2.filter.SuffixFileFilter
-
- All Implemented Interfaces:
java.io.Serializable
,FileFilter
public class SuffixFileFilter extends java.lang.Object implements FileFilter, java.io.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:
- "https://commons.apache.org/proper/commons-io/", Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SuffixFileFilter(java.lang.String... suffixes)
Constructs a new Suffix file filter for an array of suffixes.SuffixFileFilter(java.util.List<java.lang.String> suffixes)
Constructs a new Suffix file filter for a list of suffixes.SuffixFileFilter(IOCase caseSensitivity, java.lang.String... suffixes)
Constructs a new Suffix file filter for an array of suffixes specifying case-sensitivity.SuffixFileFilter(IOCase caseSensitivity, java.util.List<java.lang.String> suffixes)
Constructs a new Suffix file filter for a list of suffixes specifying case-sensitivity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
accept(FileSelectInfo fileSelectInfo)
Checks to see if the file name ends with the suffix.java.lang.String
toString()
Provides a String representation of this file filter.
-
-
-
Constructor Detail
-
SuffixFileFilter
public SuffixFileFilter(IOCase caseSensitivity, java.util.List<java.lang.String> suffixes)
Constructs a new Suffix file filter for a list of suffixes specifying case-sensitivity.- Parameters:
suffixes
- the suffixes to allow, must not be nullcaseSensitivity
- how to handle case sensitivity, null means case-sensitive
-
SuffixFileFilter
public SuffixFileFilter(IOCase caseSensitivity, java.lang.String... suffixes)
Constructs a new Suffix file filter for an array of suffixes specifying case-sensitivity.- Parameters:
suffixes
- the suffixes to allow, must not be nullcaseSensitivity
- how to handle case sensitivity, null means case-sensitive
-
SuffixFileFilter
public SuffixFileFilter(java.util.List<java.lang.String> suffixes)
Constructs a new Suffix file filter for a list of suffixes.- Parameters:
suffixes
- the suffixes to allow, must not be null
-
SuffixFileFilter
public SuffixFileFilter(java.lang.String... suffixes)
Constructs a new Suffix file filter for an array of suffixes.- Parameters:
suffixes
- the suffixes to allow, must not be null
-
-
Method Detail
-
accept
public boolean accept(FileSelectInfo fileSelectInfo)
Checks to see if the file name ends with the suffix.- Specified by:
accept
in interfaceFileFilter
- Parameters:
fileSelectInfo
- the File to check- Returns:
- true if the file name ends with one of our suffixes
-
toString
public java.lang.String toString()
Provides a String representation of this file filter.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a String representation
-
-