org.clapper.util.io
Class RegexFileFilter

java.lang.Object
  extended by org.clapper.util.io.RegexFileFilter
All Implemented Interfaces:
java.io.FileFilter

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.

Version:
$Revision: 5812 $
Author:
Copyright © 2004-2007 Brian M. Clapper
See Also:
AndFileFilter, OrFileFilter, NotFileFilter, RegexFilenameFilter

Constructor Summary
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.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegexFileFilter

public RegexFileFilter(java.lang.String regex,
                       FileFilterMatchType matchType)
                throws java.util.regex.PatternSyntaxException
Construct a new RegexFileFilter using the specified pattern.

Parameters:
regex - the regular expression to add
matchType - FileFilterMatchType.FILENAME to match just the filename, FileFilterMatchType.PATH to match the path (via java.io.File.getPath())
Throws:
java.util.regex.PatternSyntaxException - bad regular expression

RegexFileFilter

public RegexFileFilter(java.lang.String regex,
                       int regexFlags,
                       FileFilterMatchType matchType)
                throws java.util.regex.PatternSyntaxException
Construct a new RegexFileFilter using the specified pattern.

Parameters:
regex - the regular expression to add
regexFlags - 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())
Throws:
java.util.regex.PatternSyntaxException - bad regular expression
Method Detail

accept

public 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.

Specified by:
accept in interface java.io.FileFilter
Parameters:
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.
Returns:
true if the file matches, false if it doesn't


Copyright © 2004-2007 Brian M. Clapper. All Rights Reserved.