FileDocCategorySizeDatePackage
FTPFileList.javaAPI DocApache Commons NET 1.4.1 API8162Sat Dec 03 10:05:50 GMT 2005org.apache.commons.net.ftp

FTPFileList

public class FTPFileList extends 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.
author
Steve Cohen
version
$Id: FTPFileList.java 165675 2005-05-02 20:09:55Z rwinston $
see
org.apache.commons.net.ftp.FTPClient#createFileList
see
org.apache.commons.net.ftp.FTPFileIterator
see
org.apache.commons.net.ftp.FTPFileEntryParser
see
org.apache.commons.net.ftp.FTPListParseEngine
deprecated
This class is deprecated as of version 1.2 and will be removed in version 2.0 -- use FTPFileParseEngine instead.

Fields Summary
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
private static final int
EMPTY_DIR
private status code for an empty directory
Constructors Summary
private FTPFileList(FTPFileEntryParser parser, String encoding)
The only constructor for FTPFileList, private because construction only invoked at create()

param
parser a FTPFileEntryParser value that knows how to parse the entries returned by a particular FTP site.
param
encoding The encoding to use.


                                             
         
    
        this.parser = parser;
        this.lines = new LinkedList();
    
Methods Summary
public static org.apache.commons.net.ftp.FTPFileListcreate(java.io.InputStream stream, FTPFileEntryParser parser, java.lang.String encoding)
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.

param
stream The input stream created by reading the socket on which the output of the LIST command was returned
param
parser the default FTPFileEntryParser to be used by this object. This may later be changed using the init() method.
param
encoding The encoding to use
return
the FTPFileList created, with an initialized of unparsed lines of output. Will be null if the listing cannot be read from the stream.
exception
IOException Thrown on any failure to read from the socket.

        FTPFileList list = new FTPFileList(parser, encoding);
        list.readStream(stream, encoding);
        parser.preParse(list.lines);
        return list;
    
public static org.apache.commons.net.ftp.FTPFileListcreate(java.io.InputStream stream, FTPFileEntryParser parser)
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.

param
stream The input stream created by reading the socket on which the output of the LIST command was returned
param
parser the default FTPFileEntryParser to be used by this object. This may later be changed using the init() method.
return
the FTPFileList created, with an initialized of unparsed lines of output. Will be null if the listing cannot be read from the stream.
exception
IOException Thrown on any failure to read from the socket.
deprecated
The version of this method which takes an encoding should be used.

    	return create(stream, parser, null);
    
public FTPFile[]getFiles()
returns an array of FTPFile objects for all the files in the directory listing

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

        return iterator().getFiles();
    
java.util.ListgetLines()
Package private accessor for the collection of raw input lines.

return
vector containing all the raw input lines returned from the FTP server

        return this.lines;
    
FTPFileEntryParsergetParser()
Accessor for this object's default parser.

return
this object's default parser.

        return this.parser;
    
public FTPFileIteratoriterator()
create an iterator over this list using the parser with which this list was initally created

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

        return new FTPFileIterator(this);
    
public FTPFileIteratoriterator(FTPFileEntryParser parser)
create an iterator over this list using the supplied parser

param
parser The user-supplied parser with which the list is to be iterated, may be different from this list's default parser.
return
an iterator over this list using the supplied parser.

        return new FTPFileIterator(this, parser);
    
public voidreadStream(java.io.InputStream stream, java.lang.String encoding)
internal method for reading the input into the lines vector.

param
stream The socket stream on which the input will be read.
param
encoding The encoding to use.
exception
IOException thrown on any failure to read the stream

        BufferedReader reader = new BufferedReader(new InputStreamReader(stream, encoding));

        String line = this.parser.readNextEntry(reader);

        while (line != null)
        {
            this.lines.add(line);
            line = this.parser.readNextEntry(reader);
        }
        reader.close();
    
public voidreadStream(java.io.InputStream stream)
internal method for reading the input into the lines vector.

param
stream The socket stream on which the input will be read.
exception
IOException thrown on any failure to read the stream
deprecated
The version of this method which takes an encoding should be used.

	 readStream(stream, null);