uk.org.retep.util.io
Class PatternFileFilter

java.lang.Object
  extended by uk.org.retep.util.io.PatternFileFilter
All Implemented Interfaces:
java.io.FileFilter
Direct Known Subclasses:
PackageFileFilter, PatternFileFilter.Exclude, PatternFileFilter.Include

public abstract class PatternFileFilter
extends java.lang.Object
implements java.io.FileFilter

Author:
peter

Nested Class Summary
static class PatternFileFilter.Exclude
          An Exclude filter, where all files that do not match, but are under the base directory are included.
static class PatternFileFilter.Include
          An Include filter, where all files that match are included.
 
Field Summary
protected static java.lang.String DOT
           
protected static java.lang.String DOT_REGEX
           
 
Constructor Summary
PatternFileFilter(java.io.File baseDirectory)
          Construct an empty filter
PatternFileFilter(java.io.File baseDirectory, java.util.Collection<?> patterns)
          Construct a filter using the supplied patterns
PatternFileFilter(java.io.File baseDirectory, java.util.regex.Pattern... patterns)
          Construct a filter using the supplied patterns
PatternFileFilter(java.io.File baseDirectory, java.lang.String... patterns)
          Construct a filter using the supplied patterns
 
Method Summary
 void add(java.util.regex.Pattern pattern)
          Add a Pattern to the filter.
 void add(java.lang.String pattern)
          Add a pattern to the filter.
 void addAll(java.util.Collection<?> patterns)
          Add a Collection of pattern's to the filter.
 void addAll(java.util.regex.Pattern... patterns)
          Add an array of Pattern's to the filter
 void addAll(java.lang.String... patterns)
          Add an array of Patterns to the filter
static java.lang.String convertPackage(java.lang.String pkg)
          Convert all File.separator characters into a valid Regex string
protected  java.util.regex.Matcher getMatcher(java.util.regex.Pattern pattern, java.lang.CharSequence seq)
          Get a Matcher for the supplied Pattern.
 boolean inScope(java.io.File file)
          Is the file in a subdirectory of the base directory.
 boolean matches(java.io.File file)
          Match the file to the registered Patterns.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.io.FileFilter
accept
 

Field Detail

DOT

protected static final java.lang.String DOT
See Also:
Constant Field Values

DOT_REGEX

protected static final java.lang.String DOT_REGEX
Constructor Detail

PatternFileFilter

public PatternFileFilter(java.io.File baseDirectory)
Construct an empty filter

Parameters:
baseDirectory -

PatternFileFilter

public PatternFileFilter(java.io.File baseDirectory,
                         java.util.regex.Pattern... patterns)
Construct a filter using the supplied patterns

Parameters:
baseDirectory -
patterns -

PatternFileFilter

public PatternFileFilter(java.io.File baseDirectory,
                         java.lang.String... patterns)
Construct a filter using the supplied patterns

Parameters:
baseDirectory -
patterns -

PatternFileFilter

public PatternFileFilter(java.io.File baseDirectory,
                         java.util.Collection<?> patterns)
Construct a filter using the supplied patterns

Parameters:
baseDirectory -
patterns - Collection that can contain either Pattern or String objects.
Method Detail

getMatcher

protected final java.util.regex.Matcher getMatcher(java.util.regex.Pattern pattern,
                                                   java.lang.CharSequence seq)
Get a Matcher for the supplied Pattern. This will cache the Matcher, so subsequent calls for the same Pattern will return the same Matcher.

Parameters:
pattern - Pattern to get a Matcher for
seq - CharSequence to set the Matcher against
Returns:

convertPackage

public static java.lang.String convertPackage(java.lang.String pkg)
Convert all File.separator characters into a valid Regex string

Parameters:
pkg - directory path, i.e. "a/b/c"
Returns:
"a\\/b\\/c" (or on Windows, "a\\\\b\\\\c"

add

public final void add(java.util.regex.Pattern pattern)
Add a Pattern to the filter.

Parameters:
pattern - Pattern to add

addAll

public final void addAll(java.util.regex.Pattern... patterns)
Add an array of Pattern's to the filter

Parameters:
patterns -

addAll

public final void addAll(java.util.Collection<?> patterns)
Add a Collection of pattern's to the filter. Here the elements must be either a Pattern or String.

Parameters:
patterns -

add

public void add(java.lang.String pattern)
Add a pattern to the filter. Here we compile directly into a Pattern but subclasses may override this behaviour.

Parameters:
pattern -

addAll

public final void addAll(java.lang.String... patterns)
Add an array of Patterns to the filter

Parameters:
patterns -

inScope

public final boolean inScope(java.io.File file)
Is the file in a subdirectory of the base directory. This method uses the absolute path, so it should return false if a symlink links the file to outside of the basedirectory.

Parameters:
file - File to test
Returns:
true if file is underneath the base directory, it is a true file and it's readable.

matches

public final boolean matches(java.io.File file)
Match the file to the registered Patterns.

Parameters:
file - File to test
Returns:
true if any Pattern matches.


Copyright © 1998-2010 Retep Development Group. All Rights Reserved.