|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ibm.are.common.DirectoryTreeBuilder
public class DirectoryTreeBuilder
The DirectoryTreeBuilder
class provides a simple interface for iterating through the
contents of a directory tree (a directory and all of its sub-directories). Options are provided
to specify how symbolic links should be handled (follow or do not follow), as well as the ability
to exclude certainly directories from being traversed when iterating through the directory tree.
It should be noted that this class uses a recursive algorithm to traverse the directory tree. Further,
the contents of the entire directory tree are stored in an internally managed list. Generally these
attributes are not problematic, but for very large directory trees this may become a performance issue.
For iterating through very large directory trees, the LargeDirTreeIterator
class
provides better performance and has a much smaller memory footprint than this class.
Field Summary | |
---|---|
static java.lang.String |
COPYRIGHT
Copyright for class bytecode |
protected java.util.ArrayList |
entireList
The entire list of items in the directory tree |
protected java.io.FileFilter |
fileFilter
File filter |
static int |
INFINITE_DEPTH
Represents no maximum depth limit when traversing the directory tree |
Constructor Summary | |
---|---|
DirectoryTreeBuilder(java.lang.String root)
Constructs a DirectoryTreeBuilder object with the specified root directory |
|
DirectoryTreeBuilder(java.lang.String root,
java.io.FileFilter filter)
Constructs a DirectoryTreeBuilder object with the specified root directory
and filter. |
Method Summary | |
---|---|
boolean |
accept(java.io.File pathname)
Determines whether or not the current file or directory should be accepted and thus made part of the iterator. |
void |
addExcludeDirectories(StringList dirList)
Adds a list of directories that will NOT be traversed by the iterator |
void |
addExcludeDirectory(java.lang.String dirName)
Adds a new directory to the list of directories that will NOT be traversed by the iterator |
protected void |
buildListOfFilesAndDirs(java.io.File rootDir,
int level)
Builds the list of files and directories in the tree. |
java.util.Iterator |
buildTree(boolean sorted)
Builds a list of the directory tree contents and returns an iterator over the list |
java.io.File |
getRootDirectory()
Retrieves the root directory for the tree |
java.util.Iterator |
getTree()
Retrieves an iterator over the entire contents of the directory tree |
int |
numberOfDirectories()
Retrieves the number of directories in the directory tree |
int |
numberOfFiles()
Retrieves the number of files in the directory tree |
void |
setFollowSymbolicLinks(boolean yesOrNo)
Sets whether or not symbolic links are followed. |
void |
setMaximumDepth(int newDepth)
Sets the maximum depth that will be traversed in the directory tree. |
void |
setNumberOfDirectories(int numberOfDirectories)
Deprecated. Sets the number of directories in the directory tree. This method is deprecated and will be removed in a future release. |
void |
setNumberOfFiles(int numberOfFiles)
Deprecated. Sets the number of files in the directory tree. This method is deprecated and will be removed in a future release. |
void |
setRootDirectory(java.lang.String rootDir)
Sets the root directory for the tree |
void |
sort()
Alphabetically sorts the list of the directory tree contents. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String COPYRIGHT
public static final int INFINITE_DEPTH
protected java.util.ArrayList entireList
protected java.io.FileFilter fileFilter
Constructor Detail |
---|
public DirectoryTreeBuilder(java.lang.String root)
DirectoryTreeBuilder
object with the specified root directory
root
- The root of the directory treepublic DirectoryTreeBuilder(java.lang.String root, java.io.FileFilter filter)
DirectoryTreeBuilder
object with the specified root directory
and filter.
root
- The root of the directory treefilter
- An optional filter to only select certain items in the treeMethod Detail |
---|
public void addExcludeDirectory(java.lang.String dirName)
dirName
- The name of the directory to add. Must be the full path name of the directory.public void addExcludeDirectories(StringList dirList)
dirList
- The list of directories to add. Each directory must be the full path name of the directory.public java.util.Iterator buildTree(boolean sorted)
sorted
- Whether or not the contents within each directory are sorted alphabetically
public void sort()
public java.util.Iterator getTree()
public int numberOfDirectories()
public void setNumberOfDirectories(int numberOfDirectories)
numberOfDirectories
- The number of directoriespublic int numberOfFiles()
public void setNumberOfFiles(int numberOfFiles)
numberOfFiles
- The number of filespublic java.io.File getRootDirectory()
public void setRootDirectory(java.lang.String rootDir)
rootDir
- The root directory for the treepublic void setFollowSymbolicLinks(boolean yesOrNo)
yesOrNo
- true
if symbolic links should be followed, false
if they should notpublic void setMaximumDepth(int newDepth)
newDepth
- The maximum depth that will be traversed in the directory tree.protected void buildListOfFilesAndDirs(java.io.File rootDir, int level)
rootDir
- The directory tree rootlevel
- The current level (i.e. as we are traversing) within the directory treepublic boolean accept(java.io.File pathname)
true
accept
in interface java.io.FileFilter
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |