public class MultipleRegexFilenameFilter
extends java.lang.Object
implements java.io.FilenameFilter
MultipleRegexFilenameFilter implements a java.io.FilenameFilter that matches file names and path names using one or more regular expressions. A MultipleRegexFilenameFilter contains two sets of regular expressions, an accept set and a reject set. To be accepted, a file name must not match any of the patterns in the reject set, and it must match at least one of the patterns in the accept set. If the reject set is empty, then no explicit rejections are done. However, if the accept set is empty, then all files are assumed to be accepted. (i.e., It's as if the accept set contained a single "^.*$" pattern.)
A MultipleRegexFilenameFilter can be configured to operate on just the simple file name, or on the file's path.
MultipleRegexFilenameFilter uses the java.util.regex regular expression classes, so it requires JDK 1.4 or newer.
CombinationFilenameFilter
,
CombinationFileFilter
Modifier and Type | Class and Description |
---|---|
static class |
MultipleRegexFilenameFilter.MatchType
Match types
|
Constructor and Description |
---|
MultipleRegexFilenameFilter(MultipleRegexFilenameFilter.MatchType matchType)
Construct a new MultipleRegexFilenameFilter.
|
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.
|
void |
addAcceptPattern(java.lang.String pattern)
Add an "accept" pattern to this filter.
|
void |
addRejectPattern(java.lang.String pattern)
Add an "accept" pattern to this filter.
|
public MultipleRegexFilenameFilter(MultipleRegexFilenameFilter.MatchType matchType)
matchType
- MatchType.FILENAME to match just the
filename, MatchType.PATH to match the pathpublic void addAcceptPattern(java.lang.String pattern) throws java.util.regex.PatternSyntaxException
pattern
- the regular expression to addjava.util.regex.PatternSyntaxException
- bad regular expressionaddRejectPattern(java.lang.String)
public void addRejectPattern(java.lang.String pattern) throws java.util.regex.PatternSyntaxException
pattern
- the regular expression to addjava.util.regex.PatternSyntaxException
- bad regular expressionaddAcceptPattern(java.lang.String)
public 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 MatchType.FILENAME. Used to
build the path to match when the match type is
MatchType.PATHname
- the file name