org.marketcetera.util.file
Class SmartLinksDirectoryWalker

java.lang.Object
  extended by org.apache.commons.io.DirectoryWalker
      extended by org.marketcetera.util.file.SmartLinksDirectoryWalker

public abstract class SmartLinksDirectoryWalker
extends DirectoryWalker

A DirectoryWalker which provides convenience methods to initiate traversal, and (optionally) does not follow symbolic links.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.commons.io.DirectoryWalker
DirectoryWalker.CancelException
 
Constructor Summary
protected SmartLinksDirectoryWalker(boolean followLinks)
          Constructor mirroring superclass constructor.
protected SmartLinksDirectoryWalker(boolean followLinks, FileFilter filter, int depthLimit)
          Constructor mirroring superclass constructor.
protected SmartLinksDirectoryWalker(boolean followLinks, IOFileFilter directoryFilter, IOFileFilter fileFilter, int depthLimit)
          Constructor mirroring superclass constructor.
 
Method Summary
 void apply(File root)
          Traverses the file tree rooted at the given root.
 void apply(File root, Collection results)
          Traverses the file tree rooted at the given root.
 void apply(String name)
          Traverses the file tree rooted at the file with the given name.
 void apply(String name, Collection results)
          Traverses the file tree rooted at the file with the given name.
 boolean getFollowLinks()
          Returns true if symbolic links to directories should be followed during traversal.
protected  boolean handleDirectory(File directory, int depth, Collection results)
          Returns false if the given directory is a symbolic link to a directory, and links are not to be followed, thereby blocking following the link during traversal.
 
Methods inherited from class org.apache.commons.io.DirectoryWalker
checkIfCancelled, handleCancelled, handleDirectoryEnd, handleDirectoryStart, handleEnd, handleFile, handleIsCancelled, handleRestricted, handleStart, walk
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SmartLinksDirectoryWalker

protected SmartLinksDirectoryWalker(boolean followLinks)
Constructor mirroring superclass constructor.

Parameters:
followLinks - True if links should be followed.
See Also:
DirectoryWalker.DirectoryWalker()

SmartLinksDirectoryWalker

protected SmartLinksDirectoryWalker(boolean followLinks,
                                    FileFilter filter,
                                    int depthLimit)
Constructor mirroring superclass constructor.

Parameters:
followLinks - True if links should be followed.
filter - The filter to apply. It may be null, meaning visit all files.
depthLimit - Controls to what depth the hierarchy is navigated. Less than 0 means unlimited.
See Also:
DirectoryWalker.DirectoryWalker(FileFilter,int)

SmartLinksDirectoryWalker

protected SmartLinksDirectoryWalker(boolean followLinks,
                                    IOFileFilter directoryFilter,
                                    IOFileFilter fileFilter,
                                    int depthLimit)
Constructor mirroring superclass constructor.

Parameters:
followLinks - True if links should be followed.
directoryFilter - The filter to apply to directories. It may be null, meaning visit all directories.
fileFilter - The filter to apply to files. It may be null, meaning visit all directories.
depthLimit - Controls to what depth the hierarchy is navigated. Less than 0 means unlimited.
See Also:
DirectoryWalker.DirectoryWalker(IOFileFilter,IOFileFilter,int)
Method Detail

handleDirectory

protected boolean handleDirectory(File directory,
                                  int depth,
                                  Collection results)
                           throws IOException
Returns false if the given directory is a symbolic link to a directory, and links are not to be followed, thereby blocking following the link during traversal. In this case, it also invokes DirectoryWalker.handleFile(File,int,Collection) on the link.

Overrides:
handleDirectory in class DirectoryWalker
Throws:
IOException
See Also:
DirectoryWalker.handleDirectory(File,int,Collection)

getFollowLinks

public boolean getFollowLinks()
Returns true if symbolic links to directories should be followed during traversal.

Returns:
True if so.

apply

public void apply(File root,
                  Collection results)
           throws IOException
Traverses the file tree rooted at the given root. The root may be nonexistent (no-op) or a plain file (which becomes the only file visited).

Parameters:
root - The root.
results - An object passed intact into DirectoryWalker callbacks.
Throws:
IOException - Thrown if an I/O error occurs.

apply

public void apply(File root)
           throws IOException
Traverses the file tree rooted at the given root. The root may be nonexistent (no-op) or a plain file (which becomes the only file visited). The results argument in all DirectoryWalker callbacks will be null.

Parameters:
root - The root.
Throws:
IOException - Thrown if an I/O error occurs.

apply

public void apply(String name,
                  Collection results)
           throws IOException
Traverses the file tree rooted at the file with the given name. The root may be nonexistent (no-op) or a plain file (which becomes the only file visited).

Parameters:
name - The file name.
results - An object passed intact into DirectoryWalker callbacks.
Throws:
IOException - Thrown if an I/O error occurs.

apply

public void apply(String name)
           throws IOException
Traverses the file tree rooted at the file with the given name. The root may be nonexistent (no-op) or a plain file (which becomes the only file visited). The results argument in all DirectoryWalker callbacks will be null.

Parameters:
name - The file name.
Throws:
IOException - Thrown if an I/O error occurs.


Copyright © 2012. All Rights Reserved.