public class RegexFilenameFilter
extends java.lang.Object
implements java.io.FilenameFilter
RegexFilenameFilter implements a java.io.FilenameFilter
class that matches files using a regular expression. Multiple regular
expression filters can be combined using AndFilenameFilter
and/or OrFilenameFilter
objects.
A RegexFilenameFilter can be configured to operate on just the simple file name, or on the file's path.
RegexFilenameFilter uses the java.util.regex regular expression classes.
Constructor and Description |
---|
RegexFilenameFilter(java.lang.String regex)
Construct a new RegexFilenameFilter using the specified
pattern, with an implied match type of
FileFilterMatchType.FILENAME.
|
RegexFilenameFilter(java.lang.String regex,
FileFilterMatchType matchType)
Construct a new RegexFilenameFilter using the specified
pattern.
|
RegexFilenameFilter(java.lang.String regex,
int regexFlags,
FileFilterMatchType matchType)
Construct a new RegexFilenameFilter using the specified
pattern.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(java.io.File dir,
java.lang.String name)
Determine whether a file is to be accepted or not, based on the
regular expressions in the reject and accept lists.
|
public RegexFilenameFilter(java.lang.String regex) throws java.util.regex.PatternSyntaxException
regex
- the regular expression to addjava.util.regex.PatternSyntaxException
- bad regular expressionpublic RegexFilenameFilter(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 RegexFilenameFilter(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 dir, java.lang.String name)
accept
in interface java.io.FilenameFilter
dir
- The directory containing the file. Ignored if
the match type is FileFilterMatchType.FILENAME.
Used to build the path to match when the match type is
FileFilterMatchType.PATHname
- the file name