org.apache.commons.net.ftp
Class FTPFileListParserImpl

java.lang.Object
  |
  +--org.apache.commons.net.ftp.FTPFileListParserImpl
All Implemented Interfaces:
FTPFileEntryParser, FTPFileListParser
Direct Known Subclasses:
EnterpriseUnixFTPEntryParser, NTFTPEntryParser, OS2FTPEntryParser, UnixFTPEntryParser, VMSFTPEntryParser

public abstract class FTPFileListParserImpl
extends java.lang.Object
implements FTPFileListParser, FTPFileEntryParser

This abstract class implements both the older FTPFileListParser and newer FTPFileEntryParser interfaces with default functionality. All the classes in the parser subpackage inherit from this.

Author:
Steve Cohen

Field Summary
protected  org.apache.oro.text.regex.PatternMatcher _matcher_
          Internal PatternMatcher object used by the parser.
private  org.apache.oro.text.regex.Pattern pattern
          internal pattern the matcher tries to match, representing a file entry
private  org.apache.oro.text.regex.MatchResult result
          internal match result used by the parser
 
Constructor Summary
FTPFileListParserImpl(java.lang.String regex)
          The constructor for a MatchApparatus object.
 
Method Summary
 int getGroupCnt()
          Convenience method delegates to the internal MatchResult's groups() method.
 java.lang.String getGroupsAsString()
          For debugging purposes - returns a string shows each match group by number.
 java.lang.String group(int matchnum)
          Convenience method delegates to the internal MatchResult's group() method.
 boolean matches(java.lang.String s)
          Convenience method delegates to the internal MatchResult's matches() method.
 FTPFile[] parseFileList(java.io.InputStream listStream)
          Parses an FTP server file listing and converts it into a usable format in the form of an array of FTPFile instances.
 java.lang.String readNextEntry(java.io.BufferedReader reader)
          Reads the next entry using the supplied BufferedReader object up to whatever delemits one entry from the next.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.net.ftp.FTPFileEntryParser
parseFTPEntry
 

Field Detail

pattern

private org.apache.oro.text.regex.Pattern pattern
internal pattern the matcher tries to match, representing a file entry


result

private org.apache.oro.text.regex.MatchResult result
internal match result used by the parser


_matcher_

protected org.apache.oro.text.regex.PatternMatcher _matcher_
Internal PatternMatcher object used by the parser. It has protected scope in case subclasses want to make use of it for their own purposes.

Constructor Detail

FTPFileListParserImpl

public FTPFileListParserImpl(java.lang.String regex)
The constructor for a MatchApparatus object.

Parameters:
regex - The regular expression with which this object is initialized.
Throws:
java.lang.IllegalArgumentException - Thrown if the regular expression is unparseable. Should not be seen in normal conditions. It it is seen, this is a sign that a subclass has been created with a bad regular expression. Since the parser must be created before use, this means that any bad parser subclasses created from this will bomb very quickly, leading to easy detection.
Method Detail

parseFileList

public FTPFile[] parseFileList(java.io.InputStream listStream)
                        throws java.io.IOException
Parses an FTP server file listing and converts it into a usable format in the form of an array of FTPFile instances. If the file list contains no files, null should be returned, otherwise an array of FTPFile instances representing the files in the directory is returned.

Specified by:
parseFileList in interface FTPFileListParser
Parameters:
listStream - The InputStream from which the file list should be read.
Returns:
The list of file information contained in the given path. null if the list could not be obtained or if there are no files in the directory.
Throws:
java.io.IOException - If an I/O error occurs reading the listStream.

matches

public boolean matches(java.lang.String s)
Convenience method delegates to the internal MatchResult's matches() method.

Parameters:
s - the String to be matched
Returns:
true if s matches this object's regular expression.

getGroupCnt

public int getGroupCnt()
Convenience method delegates to the internal MatchResult's groups() method.

Returns:
the number of groups() in the internal MatchResult.

group

public java.lang.String group(int matchnum)
Convenience method delegates to the internal MatchResult's group() method.

Parameters:
matchnum - match group number to be retrieved
Returns:
the content of the matchnum'th group of the internal match or null if this method is called without a match having been made.

getGroupsAsString

public java.lang.String getGroupsAsString()
For debugging purposes - returns a string shows each match group by number.

Returns:
a string shows each match group by number.

readNextEntry

public java.lang.String readNextEntry(java.io.BufferedReader reader)
                               throws java.io.IOException
Reads the next entry using the supplied BufferedReader object up to whatever delemits one entry from the next. This default implementation simply calls BufferedReader.readLine().

Specified by:
readNextEntry in interface FTPFileEntryParser
Parameters:
reader - The BufferedReader object from which entries are to be read.
Returns:
A string representing the next ftp entry or null if none found.
Throws:
java.io.IOException - thrown on any IO Error reading from the reader.