dfs 2004/01/06 10:52:56 Modified: net/src/java/org/apache/commons/net/ftp FTPClient.java Log: Added caching of system name so that calls to getSystemName() don't travel across the wire when autodetecting the FTPFileEntryParser to use every time listFiles is called. Revision Changes Path 1.23 +26 -8 jakarta-commons/net/src/java/org/apache/commons/net/ftp/FTPClient.java Index: FTPClient.java =================================================================== RCS file: /home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/ftp/FTPClient.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- FTPClient.java 5 Jan 2004 23:56:49 -0000 1.22 +++ FTPClient.java 6 Jan 2004 18:52:56 -0000 1.23 @@ -251,7 +251,11 @@ private int __fileType, __fileFormat, __fileStructure, __fileTransferMode; private boolean __remoteVerificationEnabled; private long __restartOffset; - private FTPFileEntryParserFactory parserFactory; + private FTPFileEntryParserFactory __parserFactory; + + // __systemName is a cached values that should not be referenced directly + // except when assigned in getSystemName and __initDefaults. + private String __systemName; /*** * Default FTPClient constructor. Creates a new FTPClient instance @@ -267,7 +271,7 @@ __initDefaults(); __dataTimeout = -1; __remoteVerificationEnabled = true; - parserFactory = new DefaultFTPFileEntryParserFactory(); + __parserFactory = new DefaultFTPFileEntryParserFactory(); } @@ -281,6 +285,7 @@ __fileFormat = FTP.NON_PRINT_TEXT_FORMAT; __fileTransferMode = FTP.STREAM_TRANSFER_MODE; __restartOffset = 0; + __systemName = null; } private String __parsePathname(String reply) @@ -530,14 +535,14 @@ /** * set the factory used for parser creation to the supplied factory object. * - * @param parserFactory + * @param __parserFactory * factory object used to create FTPFileEntryParsers * * @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory * @see org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory */ public void setParserFactory(FTPFileEntryParserFactory parserFactory) { - this.parserFactory = parserFactory; + __parserFactory = parserFactory; } @@ -1795,6 +1800,11 @@ /*** * Fetches the system type name from the server and returns the string. + * This value is cached for the duration of the connection after the + * first call to this method. In other words, only the first time + * that you invoke this method will it issue a SYST command to the + * FTP server. FTPClient will remember the value and return the + * cached value until a call to disconnect. * <p> * @return The system type name obtained from the server. null if the * information could not be obtained. @@ -1812,10 +1822,10 @@ // Technically, we should expect a NAME_SYSTEM_TYPE response, but // in practice FTP servers deviate, so we soften the condition to // a positive completion. - if (FTPReply.isPositiveCompletion(syst())) - return ((String)_replyLines.elementAt(0)).substring(4); + if (__systemName == null && FTPReply.isPositiveCompletion(syst())) + __systemName = ((String)_replyLines.elementAt(0)).substring(4); - return null; + return __systemName; } @@ -2045,7 +2055,7 @@ } FTPFileEntryParser parser = - this.parserFactory.createFileEntryParser(parserKey); + __parserFactory.createFileEntryParser(parserKey); FTPFileList list = createFileList(pathname, parser); return list.getFiles(); } @@ -2366,3 +2376,11 @@ return null; } } + +/* Emacs configuration + * Local variables: ** + * mode: java ** + * c-basic-offset: 4 ** + * indent-tabs-mode: nil ** + * End: ** + */
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]