org.cdlib.xtf.util
Class FileWalker

Object
  extended by FileWalker

public abstract class FileWalker
extends Object

The FileWalker class is a utility class that simplifies traversing all the files in a file-system directory, and optionally, in any sub-directories.

To use this class, create a derived class that implements the abstract method processFile() . Then, create an instance of the derived class and call the processFiles() method.


Field Summary
private  File mBasePath
          Local copy of the path to the base directory to process (as passed into processFiles() .
private  boolean mContinueProcessing
          Flag indicating whether file processing should continue or stop (set by the value returned from the derived processFile(String, String, String, String) method.)
 
Constructor Summary
FileWalker()
           
 
Method Summary
protected abstract  boolean processFile(String basePath, String subPath, String fileName, String fileExt)
          File processing function.
private  void processFiles(File theFile, boolean subDirs)
          Internal recursive directory/file iterating function.
 void processFiles(String baseDir, boolean subDirs)
          Process all the files in the specified directory, and optionally in all its sub-directories.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mBasePath

private File mBasePath
Local copy of the path to the base directory to process (as passed into processFiles() .


mContinueProcessing

private boolean mContinueProcessing
Flag indicating whether file processing should continue or stop (set by the value returned from the derived processFile(String, String, String, String) method.)

Constructor Detail

FileWalker

public FileWalker()
Method Detail

processFiles

public void processFiles(String baseDir,
                         boolean subDirs)
                  throws IOException
Process all the files in the specified directory, and optionally in all its sub-directories.

This method calls the derived processFile() to process any files found.

Parameters:
baseDir - The base directory containing files to process.

subDirs - A flag that indicates whether files in sub-directories should also be processed (true) or not (false).

Throws:
IOException

processFile

protected abstract boolean processFile(String basePath,
                                       String subPath,
                                       String fileName,
                                       String fileExt)
File processing function.

This function is called once for every file encountered in the specified base directory. This function is abstract, and requires a derived class to actually implement it.

Parameters:
basePath - The base path under which the current file was found. This path will end in a forward slash (/) character to simplify the construction of a full path/file specification for the current file.

subPath - The sub-path (if any) under which the current file was found. As with the base path, this sub-path will end in a forward slash (/) character to simplify the construction of a full path/file specification for the current file.

fileName - The name of the current file (without the extension).

fileExt - The extension of the current file (if any). If the current file has an extension, then this string will begin with a period (.), to simplify the construction of a full path/file specifiecation for the current file.

Returns:
The derived function should return true if file processing should continue, or false if file processing shouild stop.

processFiles

private void processFiles(File theFile,
                          boolean subDirs)
                   throws IOException
Internal recursive directory/file iterating function.

This function is called recursively when a file encountered is a directory and sub-directory processing is enabled.

Parameters:
theFile - The name of the current file/directory to process.

subDirs - A flag indicating whether or not sub-directories should be processed.

Throws:
IOException
Notes:
This method calls itself recursively if sub-directory processing is enabled with the subDirs parameter. Once an actual file is encountered, this method calls the derived processFile() method to actually perform some work for the file found.