@Override public FTPFile parseFTPEntry(String listEntry) { if (cachedFtpFileEntryParser != null) { FTPFile matched = cachedFtpFileEntryParser.parseFTPEntry(listEntry); if (matched != null) { return matched; } } else { for (FTPFileEntryParser ftpFileEntryParser : ftpFileEntryParsers) { FTPFile matched = ftpFileEntryParser.parseFTPEntry(listEntry); if (matched != null) { cachedFtpFileEntryParser = ftpFileEntryParser; return matched; } } } return null; } }
/** * handle the initial reading and preparsing of the list returned by * the server. After this method has completed, this object will contain * a list of unparsed entries (Strings) each referring to a unique file * on the server. * * @param stream input stream provided by the server socket. * @param encoding the encoding to be used for reading the stream * * @throws IOException * thrown on any failure to read from the sever. */ public void readServerList(InputStream stream, String encoding) throws IOException { this.entries = new LinkedList<String>(); readStream(stream, encoding); this.parser.preParse(this.entries); resetIterator(); }
/** * Internal method for reading the input into the <code>entries</code> list. * After this method has completed, <code>entries</code> will contain a * collection of entries (as defined by * <code>FTPFileEntryParser.readNextEntry()</code>), but this may contain * various non-entry preliminary lines from the server output, duplicates, * and other data that will not be part of the final listing. * * @param stream The socket stream on which the input will be read. * @param encoding The encoding to use. * * @throws IOException * thrown on any failure to read the stream */ private void readStream(InputStream stream, String encoding) throws IOException { BufferedReader reader = new BufferedReader( new InputStreamReader(stream, Charsets.toCharset(encoding))); String line = this.parser.readNextEntry(reader); while (line != null) { this.entries.add(line); line = this.parser.readNextEntry(reader); } reader.close(); }
parser.preParse(replies); for(String line : replies) { final FTPFile f = parser.parseFTPEntry(line); if(null == f) { continue;
while (count > 0 && this._internalIterator.hasPrevious()) { String entry = this._internalIterator.previous(); FTPFile temp = this.parser.parseFTPEntry(entry); if (temp == null && saveUnparseableEntries) { temp = new FTPFile(entry);
@Override public List<String> preParse(final List<String> original) { for(FTPFileEntryParser parser : parsers) { parser.preParse(original); } return original; }
/** * internal method for reading the input into the <code>lines</code> 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 */ public void readStream(InputStream stream, String encoding) throws IOException { 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(); }
while (count > 0 && this._internalIterator.hasNext()) { String entry = this._internalIterator.next(); FTPFile temp = this.parser.parseFTPEntry(entry); if (temp == null && saveUnparseableEntries) { temp = new FTPFile(entry);
/** * handle the iniitial reading and preparsing of the list returned by * the server. After this method has completed, this object will contain * a list of unparsed entries (Strings) each referring to a unique file * on the server. * * @param stream input stream provided by the server socket. * * @exception IOException * thrown on any failure to read from the sever. */ public void readServerList(InputStream stream, String encoding) throws IOException { this.entries = new LinkedList(); readStream(stream, encoding); this.parser.preParse(this.entries); resetIterator(); }
String line = this.parser.readNextEntry(reader); line = this.parser.readNextEntry(reader);
while (iter.hasNext()) { String entry = iter.next(); FTPFile temp = this.parser.parseFTPEntry(entry); if (temp == null && saveUnparseableEntries) { temp = new FTPFile(entry);
/** * handle the iniitial reading and preparsing of the list returned by * the server. After this method has completed, this object will contain * a list of unparsed entries (Strings) each referring to a unique file * on the server. * * @param stream input stream provided by the server socket. * * @exception IOException * thrown on any failure to read from the sever. */ public void readServerList(InputStream stream, String encoding) throws IOException { this.entries = new LinkedList<String>(); readStream(stream, encoding); this.parser.preParse(this.entries); resetIterator(); }
String line = this.parser.readNextEntry(reader); line = this.parser.readNextEntry(reader);
/** * Delegates to this object's parser member the job of parsing an * entry. * * @param entry A string containing one entry, as determined by the * parser's getNextEntry() method. * * @return an FTPFile object representing this entry or null if it can't be * parsed as a file */ private FTPFile parseFTPEntry(String entry) { return this.parser.parseFTPEntry(entry); }
/** * The only way to create an <code>FTPFileList</code> 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 <code>FTPFile</code> 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 <code>FTPFileEntryParser</code> to be used * by this object. This may later be changed using the init() method. * @param encoding The encoding to use * * @return the <code>FTPFileList</code> 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. */ public static FTPFileList create(InputStream stream, FTPFileEntryParser parser, String encoding) throws IOException { FTPFileList list = new FTPFileList(parser, encoding); list.readStream(stream, encoding); parser.preParse(list.lines); return list; }
public FTPFile parseFTPEntry(String listEntry) { if (cachedFtpFileEntryParser != null) { FTPFile matched = cachedFtpFileEntryParser.parseFTPEntry(listEntry); if (matched != null) { return matched; } } else { for (int iterParser=0; iterParser < ftpFileEntryParsers.length; iterParser++) { FTPFileEntryParser ftpFileEntryParser = ftpFileEntryParsers[iterParser]; FTPFile matched = ftpFileEntryParser.parseFTPEntry(listEntry); if (matched != null) { cachedFtpFileEntryParser = ftpFileEntryParser; return matched; } } } return null; } }
public FTPFile parseFTPEntry(String listEntry) { if (cachedFtpFileEntryParser != null) { FTPFile matched = cachedFtpFileEntryParser.parseFTPEntry(listEntry); if (matched != null) { return matched; } } else { for (int iterParser=0; iterParser < ftpFileEntryParsers.length; iterParser++) { FTPFileEntryParser ftpFileEntryParser = ftpFileEntryParsers[iterParser]; FTPFile matched = ftpFileEntryParser.parseFTPEntry(listEntry); if (matched != null) { cachedFtpFileEntryParser = ftpFileEntryParser; return matched; } } } return null; } }
/** * Returns an array of FTPFile objects containing the whole list of * files returned by the server as read by this object's parser. * * @return an array of FTPFile objects containing the whole list of * files returned by the server as read by this object's parser. * <p><b> * NOTE:</b> This array may contain null members if any of the * individual file listings failed to parse. The caller should * check each entry for null before referencing it. * @exception IOException */ public FTPFile[] getFiles() throws IOException { List<FTPFile> tmpResults = new LinkedList<FTPFile>(); Iterator<String> iter = this.entries.iterator(); while (iter.hasNext()) { String entry = iter.next(); FTPFile temp = this.parser.parseFTPEntry(entry); tmpResults.add(temp); } return tmpResults.toArray(new FTPFile[0]); }
@Override public FTPFile parseFTPEntry(final String line) { if(log.isDebugEnabled()) { log.debug(String.format("Parse %s", line)); } if(current != null) { final FTPFile parsed = current.parseFTPEntry(line); if(null != parsed) { return parsed; } if(log.isInfoEnabled()) { log.info(String.format("Switching parser implementation because %s failed", current)); } current = null; } for(FTPFileEntryParser parser : parsers) { final FTPFile matched = parser.parseFTPEntry(line); if(matched != null) { current = parser; if(log.isInfoEnabled()) { log.info(String.format("Caching %s parser implementation", current)); } return matched; } } log.warn(String.format("Failure parsing line %s", line)); return null; }
/** * Returns an array of FTPFile objects containing the whole list of * files returned by the server as read by this object's parser. * * @return an array of FTPFile objects containing the whole list of * files returned by the server as read by this object's parser. * <p><b> * NOTE:</b> This array may contain null members if any of the * individual file listings failed to parse. The caller should * check each entry for null before referencing it. * @exception IOException */ public FTPFile[] getFiles() throws IOException { List tmpResults = new LinkedList(); Iterator iter = this.entries.iterator(); while (iter.hasNext()) { String entry = (String) iter.next(); FTPFile temp = this.parser.parseFTPEntry(entry); tmpResults.add(temp); } return (FTPFile[]) tmpResults.toArray(new FTPFile[0]); }