org.clapper.util.io
Class RegexFilenameFilter

java.lang.Object
  extended by org.clapper.util.io.RegexFilenameFilter
All Implemented Interfaces:
java.io.FilenameFilter

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.

Version:
$Revision: 5812 $
Author:
Copyright © 2004-2007 Brian M. Clapper
See Also:
AndFilenameFilter, OrFilenameFilter, NotFilenameFilter, RegexFileFilter

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

Constructor Detail

RegexFilenameFilter

public RegexFilenameFilter(java.lang.String regex)
                    throws java.util.regex.PatternSyntaxException
Construct a new RegexFilenameFilter using the specified pattern, with an implied match type of FileFilterMatchType.FILENAME.

Parameters:
regex - the regular expression to add
Throws:
java.util.regex.PatternSyntaxException - bad regular expression

RegexFilenameFilter

public RegexFilenameFilter(java.lang.String regex,
                           FileFilterMatchType matchType)
                    throws java.util.regex.PatternSyntaxException
Construct a new RegexFilenameFilter 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

RegexFilenameFilter

public RegexFilenameFilter(java.lang.String regex,
                           int regexFlags,
                           FileFilterMatchType matchType)
                    throws java.util.regex.PatternSyntaxException
Construct a new RegexFilenameFilter 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 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.

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


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