001: /*
002: * Copyright 2001-2005 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.net.ftp;
017:
018: import java.io.BufferedReader;
019: import java.io.IOException;
020: import java.io.InputStream;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: /**
025: * This abstract class implements both the older FTPFileListParser and
026: * newer FTPFileEntryParser interfaces with default functionality.
027: * All the classes in the parser subpackage inherit from this.
028: *
029: */
030: public abstract class FTPFileEntryParserImpl implements
031: FTPFileEntryParser, FTPFileListParser {
032: /**
033: * The constructor for a FTPFileEntryParserImpl object.
034: */
035: public FTPFileEntryParserImpl() {
036: }
037:
038: /***
039: * Parses an FTP server file listing and converts it into a usable format
040: * in the form of an array of <code> FTPFile </code> instances. If the
041: * file list contains no files, <code> null </code> should be
042: * returned, otherwise an array of <code> FTPFile </code> instances
043: * representing the files in the directory is returned.
044: * <p>
045: * @param listStream The InputStream from which the file list should be
046: * read.
047: * @return The list of file information contained in the given path. null
048: * if the list could not be obtained or if there are no files in
049: * the directory.
050: * @exception java.io.IOException If an I/O error occurs reading the listStream.
051: ***/
052: public FTPFile[] parseFileList(InputStream listStream,
053: String encoding) throws IOException {
054: FTPFileList ffl = FTPFileList
055: .create(listStream, this , encoding);
056: return ffl.getFiles();
057:
058: }
059:
060: /***
061: * Parses an FTP server file listing and converts it into a usable format
062: * in the form of an array of <code> FTPFile </code> instances. If the
063: * file list contains no files, <code> null </code> should be
064: * returned, otherwise an array of <code> FTPFile </code> instances
065: * representing the files in the directory is returned.
066: * <p>
067: * @param listStream The InputStream from which the file list should be
068: * read.
069: * @return The list of file information contained in the given path. null
070: * if the list could not be obtained or if there are no files in
071: * the directory.
072: * @exception java.io.IOException If an I/O error occurs reading the listStream.
073: *
074: * @deprecated The version of this method which takes an encoding should be used.
075: ***/
076: public FTPFile[] parseFileList(InputStream listStream)
077: throws IOException {
078: return parseFileList(listStream, null);
079: }
080:
081: /**
082: * Reads the next entry using the supplied BufferedReader object up to
083: * whatever delemits one entry from the next. This default implementation
084: * simply calls BufferedReader.readLine().
085: *
086: * @param reader The BufferedReader object from which entries are to be
087: * read.
088: *
089: * @return A string representing the next ftp entry or null if none found.
090: * @exception java.io.IOException thrown on any IO Error reading from the reader.
091: */
092: public String readNextEntry(BufferedReader reader)
093: throws IOException {
094: return reader.readLine();
095: }
096:
097: /**
098: * This method is a hook for those implementors (such as
099: * VMSVersioningFTPEntryParser, and possibly others) which need to
100: * perform some action upon the FTPFileList after it has been created
101: * from the server stream, but before any clients see the list.
102: *
103: * This default implementation is a no-op.
104: *
105: * @param original Original list after it has been created from the server stream
106: *
107: * @return <code>original</code> unmodified.
108: */
109: public List preParse(List original) {
110: Iterator it = original.iterator();
111: while (it.hasNext()) {
112: String entry = (String) it.next();
113: if (null == parseFTPEntry(entry)) {
114: it.remove();
115: } else {
116: break;
117: }
118: }
119: return original;
120: }
121: }
122:
123: /* Emacs configuration
124: * Local variables: **
125: * mode: java **
126: * c-basic-offset: 4 **
127: * indent-tabs-mode: nil **
128: * End: **
129: */
|