org.apache.commons.net.ftp

Class FTPFileList


public class FTPFileList
extends java.lang.Object

This class encapsulates a listing of files from an FTP server. It is initialized with an input stream which is read and the input split into lines, each of which (after some possible initial verbiage) represents a file on the FTP server. A parser is also supplied, which is used to iterate through the internal list of lines parsing each into an FTPFile object which is returned to the caller of the iteration methods. This parser may be replaced with another, allowing the same list to be parsed with different parsers. Parsing takes place on an as-needed basis, basically, the first time a position is iterated over. This happens at the time of iteration, not prior to it as the older (FTPClient.listFiles() methods did, which required a bigger memory hit.

Version:
$Id: FTPFileList.java,v 1.13 2004/04/21 23:30:33 scohen Exp $

Author:
Steve Cohen

See Also:
org.apache.commons.net.ftp.FTPClient.createFileList, FTPFileIterator, FTPFileEntryParser, FTPListParseEngine

Field Summary

private static int
EMPTY_DIR
private status code for an empty directory
private LinkedList
lines
storage for the raw lines of input read from the FTP server
private FTPFileEntryParser
parser
the FTPFileEntryParser assigned to be used with this lister

Constructor Summary

FTPFileList(FTPFileEntryParser parser)
The only constructor for FTPFileList, private because construction only invoked at create()

Method Summary

static FTPFileList
create(InputStream stream, FTPFileEntryParser parser)
The only way to create an FTPFileList object.
FTPFile[]
getFiles()
returns an array of FTPFile objects for all the files in the directory listing
(package private) List
getLines()
Package private accessor for the collection of raw input lines.
(package private) FTPFileEntryParser
getParser()
Accessor for this object's default parser.
FTPFileIterator
iterator()
create an iterator over this list using the parser with which this list was initally created
FTPFileIterator
iterator(FTPFileEntryParser parser)
create an iterator over this list using the supplied parser
void
readStream(InputStream stream)
internal method for reading the input into the lines vector.

Field Details

EMPTY_DIR

private static final int EMPTY_DIR
private status code for an empty directory

Field Value:
-2


lines

private LinkedList lines
storage for the raw lines of input read from the FTP server


parser

private FTPFileEntryParser parser
the FTPFileEntryParser assigned to be used with this lister

Constructor Details

FTPFileList

private FTPFileList(FTPFileEntryParser parser)
The only constructor for FTPFileList, private because construction only invoked at create()

Parameters:
parser - a FTPFileEntryParser value that knows how to parse the entries returned by a particular FTP site.

Method Details

create

public static FTPFileList create(InputStream stream,
                                 FTPFileEntryParser parser)
            throws IOException
The only way to create an FTPFileList object. Invokes the private constructor and then reads the stream supplied stream to build the intermediate array of "lines" which will later be parsed into FTPFile object.

Parameters:
stream - The input stream created by reading the socket on which the output of the LIST command was returned
parser - the default FTPFileEntryParser to be used by this object. This may later be changed using the init() method.

Returns:
the FTPFileList created, with an initialized of unparsed lines of output. Will be null if the listing cannot be read from the stream.


getFiles

public FTPFile[] getFiles()
returns an array of FTPFile objects for all the files in the directory listing

Returns:
an array of FTPFile objects for all the files in the directory listinge


getLines

(package private)  List getLines()
Package private accessor for the collection of raw input lines.

Returns:
vector containing all the raw input lines returned from the FTP server


getParser

(package private)  FTPFileEntryParser getParser()
Accessor for this object's default parser.

Returns:
this object's default parser.


iterator

public FTPFileIterator iterator()
create an iterator over this list using the parser with which this list was initally created

Returns:
an iterator over this list using the list's default parser.


iterator

public FTPFileIterator iterator(FTPFileEntryParser parser)
create an iterator over this list using the supplied parser

Parameters:
parser - The user-supplied parser with which the list is to be iterated, may be different from this list's default parser.

Returns:
an iterator over this list using the supplied parser.


readStream

public void readStream(InputStream stream)
            throws IOException
internal method for reading the input into the lines vector.

Parameters:
stream - The socket stream on which the input will be read.