org.pf.file
Class FileWalker

java.lang.Object
  extended by org.pf.file.FileWalker

public class FileWalker
extends Object

This class provides services to navigate through a file directory and handle files that match a name filter.

Version:
1.2
Author:
Manfred Duchrow

Field Summary
static String PATTERN_SEPARATOR
          The character to be used to separate filename patterns (';') as String.
static char PATTERN_SEPARATOR_CHAR
          The character to be used to separate filename patterns (';').
 
Constructor Summary
FileWalker(FileHandler handler)
          Initialize the new instance with default values.
FileWalker(FileHandler handler, char digitWildcard)
          Initialize the new instance with a file handler and a wildcard character for digits.
 
Method Summary
protected  String[] extractPatterns(String pattern)
           
protected  Character getDigitWildcard()
           
protected  char getDigitWildcardChar()
           
protected  FileHandler getFileHandler()
           
protected  boolean getGoOn()
           
protected  boolean hasDigitWildcard()
           
protected  void setDigitWildcard(Character newValue)
           
 void setDigitWildcardChar(char digitWildcard)
          Sets the given character as a wildcard character to match digits ('0'-'9') only.
protected  void setFileHandler(FileHandler newValue)
           
protected  void setGoOn(boolean newValue)
           
protected  long walkThrough(String dir, FilenameFilter filter, boolean recursive)
           
 long walkThrough(String dir, String pattern, boolean recursive)
          This method starts in the given directory to search for all files matching the given pattern(s).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATTERN_SEPARATOR_CHAR

public static final char PATTERN_SEPARATOR_CHAR
The character to be used to separate filename patterns (';').

See Also:
Constant Field Values

PATTERN_SEPARATOR

public static final String PATTERN_SEPARATOR
The character to be used to separate filename patterns (';') as String.

See Also:
Constant Field Values
Constructor Detail

FileWalker

public FileWalker(FileHandler handler)
Initialize the new instance with default values.


FileWalker

public FileWalker(FileHandler handler,
                  char digitWildcard)
Initialize the new instance with a file handler and a wildcard character for digits.

Parameters:
handler - The file handler that gets all found files
digitWildcard - A character that is used as wildcard for digits in filname patterns
Method Detail

getFileHandler

protected FileHandler getFileHandler()

setFileHandler

protected void setFileHandler(FileHandler newValue)

getGoOn

protected boolean getGoOn()

setGoOn

protected void setGoOn(boolean newValue)

getDigitWildcard

protected Character getDigitWildcard()

setDigitWildcard

protected void setDigitWildcard(Character newValue)

walkThrough

public long walkThrough(String dir,
                        String pattern,
                        boolean recursive)
This method starts in the given directory to search for all files matching the given pattern(s).
There can be more than one pattern in the pattern parameter. They have to be separated by the PATTERN_SEPARATOR (';').

If recursive is true it goes down to each subdirectory and doing the same there.
For each matching file (non-directory) the defined FileHandler.handle() is called.

Parameters:
dir - The directory where to start
pattern - The file name pattern(s) for filtering out the correct files ( wildcards '*' and '?' )
recursive - If set to true, the file selection is going down to all subdirectories
Returns:
the number of found files, that have matched the given pattern.

setDigitWildcardChar

public void setDigitWildcardChar(char digitWildcard)
Sets the given character as a wildcard character to match digits ('0'-'9') only.

Parameters:
digitWildcard - The placeholder character for digits

walkThrough

protected long walkThrough(String dir,
                           FilenameFilter filter,
                           boolean recursive)

extractPatterns

protected String[] extractPatterns(String pattern)

getDigitWildcardChar

protected char getDigitWildcardChar()

hasDigitWildcard

protected boolean hasDigitWildcard()