org.apache.commons.finder
Class FileFinder

java.lang.Object
  extended by org.apache.commons.finder.FileFinder
All Implemented Interfaces:
Finder

public class FileFinder
extends java.lang.Object
implements Finder

Searches for files that match certain criteria in a directory, and typically also subdirectories.

This is a programmatic equivalent of the search functions present in many operating systems. You can be informed dynamically of events as they occur by adding a listener.

Since:
1.1
Version:
$Id: FileFinder.java 437543 2006-08-28 05:47:51Z bayard $
Author:
Henri Yandell

Field Summary
 
Fields inherited from interface org.apache.commons.finder.Finder
CAN_READ, CAN_WRITE, CANNOT_READ, CANNOT_WRITE, DAYSTART, DEPTH, DIRECTORY, EMPTY, FILE, HIDDEN, IGNORE_HIDDEN_DIRS, INAME, IPATH, IREGEX, MAXDEPTH, MIN, MINDEPTH, NAME, NEWER, NOT, NOT_EMPTY, PATH, REGEX, SIZE, TIME, VISIBLE
 
Constructor Summary
FileFinder()
          Constructor.
 
Method Summary
 void addFindListener(FindListener listener)
          Adds a FindListener that is notified when a file is found.
 java.io.File[] find(java.io.File directory)
          Find all files in the specified directory.
 java.io.File[] find(java.io.File directory, java.util.Map options)
          Finds files in the specified directory that match the given options.
 void find(java.io.File directory, java.util.Map options, java.util.List foundFiles)
          Finds files in the specified directory that match the given options.
protected  void notifyDirectoryFinished(java.io.File directory, java.io.File[] files)
          Notify all FindListeners that a directory has been finished.
protected  void notifyDirectoryStarted(java.io.File directory)
          Notify all FindListeners that a directory is being started.
protected  void notifyFileFound(java.io.File directory, java.io.File file)
          Notifies each FindListeners that a file has been found.
 void removeFindListener(FindListener listener)
          Removes a FindListener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileFinder

public FileFinder()
Constructor.

Method Detail

find

public java.io.File[] find(java.io.File directory)
Find all files in the specified directory.

Specified by:
find in interface Finder
Parameters:
directory - the directory to search in

find

public java.io.File[] find(java.io.File directory,
                           java.util.Map options)
Finds files in the specified directory that match the given options.

Specified by:
find in interface Finder
Parameters:
directory - the directory to search in
options - the options to use

find

public void find(java.io.File directory,
                 java.util.Map options,
                 java.util.List foundFiles)
Finds files in the specified directory that match the given options. The results are added to the non-null list provided.

Note: To avoid large memory allocations, avoid adding any FileListeners, and try overwriding List.add(Object o) instead.

Parameters:
directory - the directory to search in
options - the options to use
foundFiles - a List to which all found files will be added

addFindListener

public void addFindListener(FindListener listener)
Adds a FindListener that is notified when a file is found.

Specified by:
addFindListener in interface Finder
Parameters:
listener - the listener

removeFindListener

public void removeFindListener(FindListener listener)
Removes a FindListener.

Specified by:
removeFindListener in interface Finder
Parameters:
listener - the listener

notifyDirectoryStarted

protected void notifyDirectoryStarted(java.io.File directory)
Notify all FindListeners that a directory is being started.

Parameters:
directory - the directory

notifyDirectoryFinished

protected void notifyDirectoryFinished(java.io.File directory,
                                       java.io.File[] files)
Notify all FindListeners that a directory has been finished.

Parameters:
directory - the directory
files - the files that were found in the directory

notifyFileFound

protected void notifyFileFound(java.io.File directory,
                               java.io.File file)
Notifies each FindListeners that a file has been found.

Parameters:
directory - the directory being processed
file - the file that was found


Copyright © 2001-2008 The Apache Software Foundation. All Rights Reserved.