public class WildcardFileFilter extends java.lang.Object implements FileFilter, java.io.Serializable
This filter selects files and directories based on one or more wildcards. Testing is case-sensitive by default, but this can be configured.
The wildcard matcher uses the characters '?' and '*' to represent a single or multiple wildcard characters. This is the same as often found on Dos/Unix command lines.
For example, to retrieve and print all java files that have the expression test in the name in the current directory:
FileSystemManager fsManager = VFS.getManager(); FileObject dir = fsManager.toFileObject(new File(".")); FileObject[] files; files = dir.findFiles(new FileFilterSelector(new WildcardFileFilter("*test*.java"))); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); }
Modifier and Type | Field and Description |
---|---|
private IOCase |
caseSensitivity
Whether the comparison is case sensitive.
|
private static long |
serialVersionUID |
private java.util.List<java.lang.String> |
wildcards
The wildcards that will be used to match file names.
|
Constructor and Description |
---|
WildcardFileFilter(IOCase caseSensitivity,
java.util.List<java.lang.String> wildcards)
Construct a new wildcard filter for a list of wildcards specifying
case-sensitivity.
|
WildcardFileFilter(IOCase caseSensitivity,
java.lang.String... wildcards)
Construct a new wildcard filter for an array of wildcards specifying
case-sensitivity.
|
WildcardFileFilter(java.util.List<java.lang.String> wildcards)
Construct a new case-sensitive wildcard filter for a list of wildcards.
|
WildcardFileFilter(java.lang.String... wildcards)
Construct a new case-sensitive wildcard filter for an array of wildcards.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(FileSelectInfo fileInfo)
Checks to see if the file name matches one of the wildcards.
|
(package private) static java.lang.String[] |
splitOnTokens(java.lang.String text)
Splits a string into a number of tokens.
|
java.lang.String |
toString()
Provide a String representation of this file filter.
|
(package private) static boolean |
wildcardMatch(java.lang.String fileName,
java.lang.String wildcardMatcher,
IOCase caseSensitivity)
Checks a file name to see if it matches the specified wildcard matcher
allowing control over case-sensitivity.
|
private static final long serialVersionUID
private final IOCase caseSensitivity
private final java.util.List<java.lang.String> wildcards
public WildcardFileFilter(java.util.List<java.lang.String> wildcards)
wildcards
- the list of wildcards to match, not nullpublic WildcardFileFilter(IOCase caseSensitivity, java.util.List<java.lang.String> wildcards)
caseSensitivity
- how to handle case sensitivity, null means
case-sensitivewildcards
- the list of wildcards to match, not nullpublic WildcardFileFilter(java.lang.String... wildcards)
The array is not cloned, so could be changed after constructing the instance. This would be inadvisable however.
wildcards
- the array of wildcards to matchpublic WildcardFileFilter(IOCase caseSensitivity, java.lang.String... wildcards)
caseSensitivity
- how to handle case sensitivity, null means
case-sensitivewildcards
- the array of wildcards to match, not nullpublic boolean accept(FileSelectInfo fileInfo)
accept
in interface FileFilter
fileInfo
- the file to checkpublic java.lang.String toString()
toString
in class java.lang.Object
static java.lang.String[] splitOnTokens(java.lang.String text)
text
- the text to splitstatic boolean wildcardMatch(java.lang.String fileName, java.lang.String wildcardMatcher, IOCase caseSensitivity)
The wildcard matcher uses the characters '?' and '*' to represent a single or multiple (zero or more) wildcard characters. N.B. the sequence "*?" does not work properly at present in match strings.
fileName
- the file name to match onwildcardMatcher
- the wildcard string to match againstcaseSensitivity
- what case sensitivity rule to use, null means
case-sensitive