1 16 package org.apache.commons.net.ftp; 17 import java.io.BufferedReader ; 18 import java.io.IOException ; 19 import java.io.InputStream ; 20 import java.io.InputStreamReader ; 21 import java.util.LinkedList ; 22 import java.util.List ; 23 24 47 public class FTPFileList 48 { 49 52 private LinkedList lines = null; 53 56 private FTPFileEntryParser parser; 57 60 private static final int EMPTY_DIR = -2; 61 62 70 private FTPFileList (FTPFileEntryParser parser, String encoding) 71 { 72 this.parser = parser; 73 this.lines = new LinkedList (); 74 } 75 76 94 public static FTPFileList create(InputStream stream, 95 FTPFileEntryParser parser, 96 String encoding) 97 throws IOException 98 { 99 FTPFileList list = new FTPFileList(parser, encoding); 100 list.readStream(stream, encoding); 101 parser.preParse(list.lines); 102 return list; 103 } 104 105 124 public static FTPFileList create(InputStream stream, 125 FTPFileEntryParser parser) 126 throws IOException 127 { 128 return create(stream, parser, null); 129 } 130 131 132 133 141 public void readStream(InputStream stream, String encoding) throws IOException 142 { 143 BufferedReader reader = new BufferedReader (new InputStreamReader (stream, encoding)); 144 145 String line = this.parser.readNextEntry(reader); 146 147 while (line != null) 148 { 149 this.lines.add(line); 150 line = this.parser.readNextEntry(reader); 151 } 152 reader.close(); 153 } 154 155 164 public void readStream(InputStream stream) throws IOException 165 { 166 readStream(stream, null); 167 } 168 169 170 175 FTPFileEntryParser getParser() 176 { 177 return this.parser; 178 } 179 180 186 List getLines() 187 { 188 return this.lines; 189 } 190 191 197 public FTPFileIterator iterator() 198 { 199 return new FTPFileIterator(this); 200 } 201 209 public FTPFileIterator iterator(FTPFileEntryParser parser) 210 { 211 return new FTPFileIterator(this, parser); 212 } 213 214 215 222 public FTPFile[] getFiles() 223 { 224 return iterator().getFiles(); 225 } 226 227 228 229 } 230 231 238 | Popular Tags |