public class RegexFileFilter
extends java.lang.Object
implements java.io.FileFilter
RegexFileFilter implements a java.io.FileFilter
class that matches files using a regular expression. Multiple regular
expression filters can be combined using AndFileFilter
and/or OrFileFilter
objects.
A RegexFileFilter can be configured to operate on just the simple file name, or on the file's path.
RegexFileFilter uses the java.util.regex regular expression classes.
AndFileFilter
,
OrFileFilter
,
NotFileFilter
,
RegexFilenameFilter
Constructor and Description |
---|
RegexFileFilter(java.lang.String regex,
FileFilterMatchType matchType)
Construct a new RegexFileFilter using the specified
pattern.
|
RegexFileFilter(java.lang.String regex,
int regexFlags,
FileFilterMatchType matchType)
Construct a new RegexFileFilter using the specified
pattern.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(java.io.File file)
Determine whether a file is to be accepted or not, based on the
regular expressions in the reject and accept lists.
|
public RegexFileFilter(java.lang.String regex, FileFilterMatchType matchType) throws java.util.regex.PatternSyntaxException
regex
- the regular expression to addmatchType
- FileFilterMatchType.FILENAME to match just the
filename, FileFilterMatchType.PATH to match
the path (via java.io.File.getPath())java.util.regex.PatternSyntaxException
- bad regular expressionpublic RegexFileFilter(java.lang.String regex, int regexFlags, FileFilterMatchType matchType) throws java.util.regex.PatternSyntaxException
regex
- the regular expression to addregexFlags
- regular expression compilation flags (e.g.,
Pattern.CASE_INSENSITIVE). See
the Javadocs for java.util.regex for
legal values.matchType
- FileFilterMatchType.FILENAME to match just the
filename, FileFilterMatchType.PATH to match
the path (via java.io.File.getPath())java.util.regex.PatternSyntaxException
- bad regular expressionpublic boolean accept(java.io.File file)
accept
in interface java.io.FileFilter
file
- The file to test. If the match type is
FileFilterMatchType.FILENAME, then the value
of file.getPath() is compared to the regular
expression. If the match type is
FileFilterMatchType.PATH, then the value of
file.getName() is compared to the regular
expression.