|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--FileIterator
A FileIterator
provides an iterator interface for
enumerating all files in a directory. The iterator can optionally
recursively search all subdirectories.
Field Summary | |
protected boolean |
applyFilterToDirs
|
protected java.io.FileFilter |
fileFilter
|
protected java.util.Stack |
fileLists
fileLists is a stack of array iterators. |
protected int |
lastFileType
lastFileType is: 0 if last obtained element was a normal file 1 if last obtained element was a directory when first encountered 2 if last obtained element was a directory when just finished it contents The codes 1 and 2 will need to be checked when both useDirsDown
and useDirsUp are true in order to tell whether it is the first
or second time the directory is being returned. |
protected java.io.File |
nextFile
|
protected int |
nextFileType
|
protected boolean |
recurseSubdirectories
|
protected boolean |
useDirsDown
|
protected boolean |
useDirsUp
|
Constructor Summary | |
FileIterator(java.io.File f)
Constructor. |
|
FileIterator(java.io.File f,
java.io.FileFilter filter)
Constructor which specifies both a File and a
FileFilter . |
Method Summary | |
int |
getLastFileType()
Accessor function for lastFileType indicating the type of
the last returned element. |
boolean |
hasNext()
Check whether there is a next File, either file or directory, to be returned. |
boolean |
hasNextFile()
Check whether there is a next file (not a directory) to be returned. |
java.lang.Object |
next()
Returns the next file or directory as an object. |
java.io.File |
nextElement()
Returns the next element which can be either a file or a directory. |
protected java.io.File |
nextElementAll()
Returns the next file or directory. |
java.io.File |
nextFile()
Returns the next element which is a file rather than a directory. |
protected void |
pushFileArrayIterator(java.io.File subDir)
Adds a new file or new directory list onto the stack fileLists |
protected void |
pushFileArrayIterator(java.io.File[] fArray)
Adds a new file list iterator onto the stack fileLists
This is generally called with the list of files from a directory. |
void |
remove()
This is an unsupported operation and generates an exception |
void |
setDirectoryModes(boolean useDirsDown,
boolean useDirsUp)
Sets the modes for returning directories with next() or nextElement(). |
void |
setFilterMode(boolean applyFilterToDirs)
Set whether the file filter applies to directories. |
void |
setRecursive(boolean recurseSubdirectories)
Set whether subdirectories are recursively searched. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
protected int lastFileType
useDirsDown
and useDirsUp
are true in order to tell whether it is the first
or second time the directory is being returned. The value 1 is used for
all directories if recurseSubdirectories
is false.
Accessor: getLastFileType()
;protected java.util.Stack fileLists
fileLists
is a stack of array iterators. Each array iterator
is acting on an array of File
's.protected java.io.FileFilter fileFilter
protected boolean recurseSubdirectories
protected boolean useDirsDown
protected boolean useDirsUp
protected boolean applyFilterToDirs
protected java.io.File nextFile
protected int nextFileType
Constructor Detail |
public FileIterator(java.io.File f) throws java.io.FileNotFoundException
File
which is generally a
directory.public FileIterator(java.io.File f, java.io.FileFilter filter) throws java.io.FileNotFoundException
File
and a
FileFilter
.FileIteratory( File f )
Method Detail |
public void setRecursive(boolean recurseSubdirectories)
recurseSubdirectories
- If true, subdirectories are recursively searched.public void setDirectoryModes(boolean useDirsDown, boolean useDirsUp)
useDirsDown=true
and useDirsUp=false
.
Note that nextFile()
can be used instead of setting both to false.
If you set both to true, then you may use the helper function
getLastFileType()
to decide whether a directory entry is being returned
before or after the directory is listed. Strange results may occur
if you change these parameters after beginning to use next
,
nextFile
or nextElement
.useDirsDown
- If true, nextElement()
returns directories
as they are opened. This is needed for "preorder" enumeration order.useDirsUp
- If true, nextElement()
returns directories
as they are finished being processed. This is needed for "postorder"
enumeration order.public void setFilterMode(boolean applyFilterToDirs)
applyFilterToDirs
- If true, skip directories that do not match the filter.public int getLastFileType()
lastFileType
indicating the type of
the last returned element. The
value of lastFileType
is equal to:
getNext...
functions
was a normal file (not a directory).
getNext...
functions
was a directory when first encountered.
getNext...
functions
was a directory when just finished with its contents.
isFile
or isDirectory
of java.io.File
.
However, the codes 1 and 2 will need to be checked when both useDirsDown
and useDirsUp
are true in order to tell whether it is the first
or second time the directory is being returned. If useDirsDown
is true and useDirsUp
is false, then the value 1 is used for all
directories. If useDirsDown
is false and useDirsUp
is true, then the value 2 is used for all
directories. The value 1 is used for
all directories if recurseSubdirectories
is false.public boolean hasNextFile()
next()
or nextElement
is called afterwards instead of nextFile
.public java.io.File nextFile() throws java.util.NoSuchElementException
useDirsDown
and
useDirsUp
are both false.public boolean hasNext()
public java.io.File nextElement() throws java.util.NoSuchElementException
getLastFileType
to distinguish files from directories,
and to recognise when a directory is encountered for the second time.public java.lang.Object next() throws java.util.NoSuchElementException
next()
is equivalent to nextElement()
, except that next()
returns a file as an Object
.protected java.io.File nextElementAll()
useDirsDown
and useDirsUp
were true.
This is intended for internal use by nextFile()
and
nextElement
and by hasNextFile
and
hasNextElement
.
It returns the next File
(a file or a directory) both as
the returned object, and as the value of nextFile
. It
sets the value of nextFileType
to indicate the type
of File
returned.
If no next element is found, it returns null
public void remove() throws java.lang.UnsupportedOperationException
protected void pushFileArrayIterator(java.io.File subDir)
protected void pushFileArrayIterator(java.io.File[] fArray)
fileLists
This is generally called with the list of files from a directory.
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |