commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick Schoonveld <pschoonv...@yahoo.com>
Subject [PATCH] performance problem w/ FTPClient
Date Fri, 14 Mar 2003 19:45:29 GMT
I've had a little problem in the past with the
NetComponents library where ASCII files take extremely
long to upload. The problem turned out to be in the
__storeFileStream function where the class, by
default, filters for line separator characters. 

I added a function to optionally turn this feature
off. I'm not sure if it's useful for anyone else, but
it really helped me.

Thanks,
Patrick

--- FTPClient.java	Tue Feb 18 23:39:42 2003
+++
commons-net/src/java/org/apache/commons/net/ftp/FTPClient.java
Fri Mar 14 12:44:20 2003
@@ -453,6 +453,12 @@
     private OutputStream __storeFileStream(int
command, String remote)
     throws IOException
     {
+		 return __storeFileStream(command, remote, true);
+	 }
+	 
+    private OutputStream __storeFileStream(int
command, String remote, boolean filterASCII)
+    throws IOException
+    {
         OutputStream output;
         Socket socket;
 
@@ -460,7 +466,7 @@
             return null;
 
         output = socket.getOutputStream();
-        if (__fileType == ASCII_FILE_TYPE)
+        if (__fileType == ASCII_FILE_TYPE &&
filterASCII)
             output = new
ToNetASCIIOutputStream(output);
         return new
org.apache.commons.net.io.SocketOutputStream(socket,
output);
     }
@@ -1311,7 +1317,42 @@
      ***/
     public OutputStream storeFileStream(String
remote) throws IOException
     {
-        return __storeFileStream(FTPCommand.STOR,
remote);
+        return __storeFileStream(FTPCommand.STOR,
remote, true);
+    }
+	/***
+     * Returns an OutputStream through which data can
be written to store
+     * a file on the server using the given name.  If
the current file type
+     * is ASCII and the filter ASCII argument is
true, the returned OutputStream 
+	  * will convert line separators in the file to the
NETASCII format  (i.e., 
+	  * you should not attempt to create a special
OutputStream to do this).  
+	  *
+	  * If ASCII files are being sent and the filter is
enabled, there is a
+	  * significant performance reduction. If set to
false, please consider the
+	  * results.
+	  *
+	  * You must close the OutputStream when you finish
writing to it.  The 
+	  * OutputStream itself will take care of closing
the parent data connection 
+	  * socket upon being closed.  To finalize the file
transfer you must call
+     * <a href="#completePendingCommand">
completePendingCommand </a> and
+     * check its return value to verify success.
+     * <p>
+     * @param remote  The name to give the remote
file.
+     * @param filterASCII  Whether to filter ASCII
streams to convert line separators.
+     * @return An OutputStream through which the
remote file can be written.  If
+     *      the data connection cannot be opened
(e.g., the file does not
+     *      exist), null is returned (in which case
you may check the reply
+     *      code to determine the exact reason for
failure).
+     * @exception FTPConnectionClosedException
+     *      If the FTP server prematurely closes the
connection as a result
+     *      of the client being idle or some other
reason causing the server
+     *      to send FTP reply code 421.  This
exception may be caught either
+     *      as an IOException or independently as
itself.
+     * @exception IOException  If an I/O error occurs
while either sending a
+     *      command to the server or receiving a
reply from the server.
+     ***/
+    public OutputStream storeFileStream(String
remote, boolean filterASCII) throws IOException
+    {
+        return __storeFileStream(FTPCommand.STOR,
remote, filterASCII);
     }
 
     /***


=====
----------------------------------------------------------
PGP Public Key available: http://schoonveld.org/pgp/pschoonveld.pub.txt
----------------------------------------------------------

__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - establish your business online
http://webhosting.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message