org.apache.commons.io

Class DirectoryWalker<T>

    • Constructor Detail

      • DirectoryWalker

        protected DirectoryWalker()
        Construct an instance with no filtering and unlimited depth.
      • DirectoryWalker

        protected DirectoryWalker(FileFilter filter,               int depthLimit)
        Construct an instance with a filter and limit the depth navigated to.

        The filter controls which files and directories will be navigated to as part of the walk. The FileFilterUtils class is useful for combining various filters together. A null filter means that no filtering should occur and all files and directories will be visited.

        Parameters:
        filter - the filter to apply, null means visit all files
        depthLimit - controls how deep the hierarchy is navigated to (less than 0 means unlimited)
      • DirectoryWalker

        protected DirectoryWalker(IOFileFilter directoryFilter,               IOFileFilter fileFilter,               int depthLimit)
        Construct an instance with a directory and a file filter and an optional limit on the depth navigated to.

        The filters control which files and directories will be navigated to as part of the walk. This constructor uses FileFilterUtils.makeDirectoryOnly(IOFileFilter) and FileFilterUtils.makeFileOnly(IOFileFilter) internally to combine the filters. A null filter means that no filtering should occur.

        Parameters:
        directoryFilter - the filter to apply to directories, null means visit all directories
        fileFilter - the filter to apply to files, null means visit all files
        depthLimit - controls how deep the hierarchy is navigated to (less than 0 means unlimited)
    • Method Detail

      • walk

        protected final void walk(File startDirectory,        Collection<T> results)                   throws IOException
        Internal method that walks the directory hierarchy in a depth-first manner.

        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.

        Writers of subclasses should call this method to start the directory walk. Once called, this method will emit events as it walks the hierarchy. The event methods have the prefix handle.

        Parameters:
        startDirectory - the directory to start from, not null
        results - the collection of result objects, may be updated
        Throws:
        NullPointerException - if the start directory is null
        IOException - if an I/O Error occurs
      • checkIfCancelled

        protected final void checkIfCancelled(File file,                    int depth,                    Collection<T> results)                               throws IOException
        Checks whether the walk has been cancelled by calling handleIsCancelled(java.io.File, int, java.util.Collection<T>), throwing a CancelException if it has.

        Writers of subclasses should not normally call this method as it is called automatically by the walk of the tree. However, sometimes a single method, typically handleFile(java.io.File, int, java.util.Collection<T>), may take a long time to run. In that case, you may wish to check for cancellation by calling this method.

        Parameters:
        file - the current file being processed
        depth - the current file level (starting directory = 0)
        results - the collection of result objects, may be updated
        Throws:
        IOException - if an I/O Error occurs
      • handleIsCancelled

        protected boolean handleIsCancelled(File file,                        int depth,                        Collection<T> results)                             throws IOException
        Overridable callback method invoked to determine if the entire walk operation should be immediately cancelled.

        This method should be implemented by those subclasses that want to provide a public cancel() method available from another thread. The design pattern for the subclass should be as follows:

          public class FooDirectoryWalker extends DirectoryWalker {    private volatile boolean cancelled = false;    public void cancel() {        cancelled = true;    }    private void handleIsCancelled(File file, int depth, Collection results) {        return cancelled;    }    protected void handleCancelled(File startDirectory,              Collection results, CancelException cancel) {        // implement processing required when a cancellation occurs    }  } 

        If this method returns true, then the directory walk is immediately cancelled. The next callback method will be handleCancelled(java.io.File, java.util.Collection<T>, org.apache.commons.io.DirectoryWalker.CancelException).

        This implementation returns false.

        Parameters:
        file - the file or directory being processed
        depth - the current directory level (starting directory = 0)
        results - the collection of result objects, may be updated
        Returns:
        true if the walk has been cancelled
        Throws:
        IOException - if an I/O Error occurs
      • handleCancelled

        protected void handleCancelled(File startDirectory,                   Collection<T> results,                   DirectoryWalker.CancelException cancel)                        throws IOException
        Overridable callback method invoked when the operation is cancelled. The file being processed when the cancellation occurred can be obtained from the exception.

        This implementation just re-throws the DirectoryWalker.CancelException.

        Parameters:
        startDirectory - the directory that the walk started from
        results - the collection of result objects, may be updated
        cancel - the exception throw to cancel further processing containing details at the point of cancellation.
        Throws:
        IOException - if an I/O Error occurs
      • handleStart

        protected void handleStart(File startDirectory,               Collection<T> results)                    throws IOException
        Overridable callback method invoked at the start of processing.

        This implementation does nothing.

        Parameters:
        startDirectory - the directory to start from
        results - the collection of result objects, may be updated
        Throws:
        IOException - if an I/O Error occurs
      • handleDirectory

        protected boolean handleDirectory(File directory,                      int depth,                      Collection<T> results)                           throws IOException
        Overridable callback method invoked to determine if a directory should be processed.

        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.

        This implementation does nothing and returns true.

        Parameters:
        directory - the current directory being processed
        depth - the current directory level (starting directory = 0)
        results - the collection of result objects, may be updated
        Returns:
        true to process this directory, false to skip this directory
        Throws:
        IOException - if an I/O Error occurs
      • handleDirectoryStart

        protected void handleDirectoryStart(File directory,                        int depth,                        Collection<T> results)                             throws IOException
        Overridable callback method invoked at the start of processing each directory.

        This implementation does nothing.

        Parameters:
        directory - the current directory being processed
        depth - the current directory level (starting directory = 0)
        results - the collection of result objects, may be updated
        Throws:
        IOException - if an I/O Error occurs
      • filterDirectoryContents

        protected File[] filterDirectoryContents(File directory,                             int depth,                             File[] files)                                  throws IOException
        Overridable callback method invoked with the contents of each directory.

        This implementation returns the files unchanged

        Parameters:
        directory - the current directory being processed
        depth - the current directory level (starting directory = 0)
        files - the files (possibly filtered) in the directory, may be null
        Returns:
        the filtered list of files
        Throws:
        IOException - if an I/O Error occurs
        Since:
        2.0
      • handleFile

        protected void handleFile(File file,              int depth,              Collection<T> results)                   throws IOException
        Overridable callback method invoked for each (non-directory) file.

        This implementation does nothing.

        Parameters:
        file - the current file being processed
        depth - the current directory level (starting directory = 0)
        results - the collection of result objects, may be updated
        Throws:
        IOException - if an I/O Error occurs
      • handleRestricted

        protected void handleRestricted(File directory,                    int depth,                    Collection<T> results)                         throws IOException
        Overridable callback method invoked for each restricted directory.

        This implementation does nothing.

        Parameters:
        directory - the restricted directory
        depth - the current directory level (starting directory = 0)
        results - the collection of result objects, may be updated
        Throws:
        IOException - if an I/O Error occurs
      • handleDirectoryEnd

        protected void handleDirectoryEnd(File directory,                      int depth,                      Collection<T> results)                           throws IOException
        Overridable callback method invoked at the end of processing each directory.

        This implementation does nothing.

        Parameters:
        directory - the directory being processed
        depth - the current directory level (starting directory = 0)
        results - the collection of result objects, may be updated
        Throws:
        IOException - if an I/O Error occurs
      • handleEnd

        protected void handleEnd(Collection<T> results)                  throws IOException
        Overridable callback method invoked at the end of processing.

        This implementation does nothing.

        Parameters:
        results - the collection of result objects, may be updated
        Throws:
        IOException - if an I/O Error occurs

Copyright © 2002–2016 The Apache Software Foundation. All rights reserved.



NOTHING
NOTHING
Add the Maven Dependecy to your project: maven dependecy for com.amazonaws : aws-java-sdk : 1.3.14