001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.commons.net.ftp;
019 import java.io.BufferedReader;
020 import java.io.IOException;
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
031 implements FTPFileEntryParser
032 {
033 /**
034 * The constructor for a FTPFileEntryParserImpl object.
035 */
036 public FTPFileEntryParserImpl()
037 {
038 }
039
040 /**
041 * Reads the next entry using the supplied BufferedReader object up to
042 * whatever delemits one entry from the next. This default implementation
043 * simply calls BufferedReader.readLine().
044 *
045 * @param reader The BufferedReader object from which entries are to be
046 * read.
047 *
048 * @return A string representing the next ftp entry or null if none found.
049 * @exception java.io.IOException thrown on any IO Error reading from the reader.
050 */
051 public String readNextEntry(BufferedReader reader) throws IOException
052 {
053 return reader.readLine();
054 }
055 /**
056 * This method is a hook for those implementors (such as
057 * VMSVersioningFTPEntryParser, and possibly others) which need to
058 * perform some action upon the FTPFileList after it has been created
059 * from the server stream, but before any clients see the list.
060 *
061 * This default implementation removes entries that do not parse as files.
062 *
063 * @param original Original list after it has been created from the server stream
064 *
065 * @return <code>original</code> unmodified.
066 */
067 public List<String> preParse(List<String> original) {
068 Iterator<String> it = original.iterator();
069 while (it.hasNext()){
070 String entry = it.next();
071 if (null == parseFTPEntry(entry)) {
072 it.remove();
073 }
074 }
075 return original;
076 }
077 }
078
079 /* Emacs configuration
080 * Local variables: **
081 * mode: java **
082 * c-basic-offset: 4 **
083 * indent-tabs-mode: nil **
084 * End: **
085 */