Separate handleDirectory from handleDirectoryStart
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@438218 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/java/org/apache/commons/io/DirectoryWalker.java b/src/java/org/apache/commons/io/DirectoryWalker.java
index 2447364..9a5eb80 100644
--- a/src/java/org/apache/commons/io/DirectoryWalker.java
+++ b/src/java/org/apache/commons/io/DirectoryWalker.java
@@ -91,7 +91,7 @@
//-----------------------------------------------------------------------
/**
- * Internal method that walks the directory hierarchy.
+ * Internal method that walks the directory hierarchy in a depth-first manner.
* <p>
* Most users of this class do not need to call this method. This method will
* be called automatically by another (public) method on the specific subclass.
@@ -117,13 +117,13 @@
* @param results the collection of result objects, may be updated
*/
private void walk(File directory, int depth, Collection results) {
- boolean process = handleDirectoryStart(directory, depth, results);
- if (process) {
+ if (handleDirectory(directory, depth, results)) {
+ handleDirectoryStart(directory, depth, results);
int childDepth = depth + 1;
if (depthLimit < 0 || childDepth <= depthLimit) {
File[] files = (filter == null ? directory.listFiles() : directory.listFiles(filter));
if (files == null) {
- handleRestricted(directory);
+ handleRestricted(directory, results);
} else {
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
@@ -152,12 +152,11 @@
}
/**
- * Overridable callback method invoked at the start of processing each directory.
+ * Overridable callback method invoked to determine if a directory should be processed.
* <p>
- * This method returns a boolean to indicate if the directory should be examined
- * or not. If you return false, the next event received will be the
- * {@link #handleDirectoryEnd} for that directory. Note that this functionality
- * is in addition to the filtering by file filter.
+ * This method returns a boolean to indicate if the directory should be examined or not.
+ * If you return false, the entire directory and any subdirectories will be skipped.
+ * Note that this functionality is in addition to the filtering by file filter.
* <p>
* This implementation does nothing and returns true.
*
@@ -166,12 +165,25 @@
* @param results the collection of result objects, may be updated
* @return true to process this directory, false to skip this directory
*/
- protected boolean handleDirectoryStart(File directory, int depth, Collection results) {
+ protected boolean handleDirectory(File directory, int depth, Collection results) {
// do nothing - overridable by subclass
return true;
}
/**
+ * Overridable callback method invoked at the start of processing each directory.
+ * <p>
+ * This implementation does nothing.
+ *
+ * @param directory the current directory being processed
+ * @param depth the current directory level (starting directory = 0)
+ * @param results the collection of result objects, may be updated
+ */
+ protected void handleDirectoryStart(File directory, int depth, Collection results) {
+ // do nothing - overridable by subclass
+ }
+
+ /**
* Overridable callback method invoked for each (non-directory) file.
* <p>
* This implementation does nothing.
@@ -186,10 +198,13 @@
/**
* Overridable callback method invoked for each restricted directory.
+ * <p>
+ * This implementation does nothing.
*
* @param directory the restricted directory
+ * @param results the collection of result objects, may be updated
*/
- protected void handleRestricted(File directory) {
+ protected void handleRestricted(File directory, Collection results) {
// do nothing - overridable by subclass
}
@@ -198,9 +213,9 @@
* <p>
* This implementation does nothing.
*
- * @param directory The directory being processed
- * @param depth The directory level (starting directory = 0)
- * @param results The collection of files found.
+ * @param directory the directory being processed
+ * @param depth the current directory level (starting directory = 0)
+ * @param results the collection of result objects, may be updated
*/
protected void handleDirectoryEnd(File directory, int depth, Collection results) {
// do nothing - overridable by subclass
diff --git a/src/test/org/apache/commons/io/DirectoryWalkerTestCase.java b/src/test/org/apache/commons/io/DirectoryWalkerTestCase.java
index be827c6..e8a21ce 100644
--- a/src/test/org/apache/commons/io/DirectoryWalkerTestCase.java
+++ b/src/test/org/apache/commons/io/DirectoryWalkerTestCase.java
@@ -247,7 +247,7 @@
}
/** Always returns false. */
- protected boolean handleDirectoryStart(File directory, int depth, Collection results) {
+ protected boolean handleDirectory(File directory, int depth, Collection results) {
return false;
}
}