You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2012/07/13 01:43:00 UTC

svn commit: r1361003 - in /commons/proper/net/trunk/src: changes/changes.xml main/java/org/apache/commons/net/ftp/FTPClient.java

Author: sebb
Date: Thu Jul 12 23:43:00 2012
New Revision: 1361003

URL: http://svn.apache.org/viewvc?rev=1361003&view=rev
Log:
NET-465 FTPClient setSendBufferSize and setReceiveBufferSize on data socket

Modified:
    commons/proper/net/trunk/src/changes/changes.xml
    commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java

Modified: commons/proper/net/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1361003&r1=1361002&r2=1361003&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml (original)
+++ commons/proper/net/trunk/src/changes/changes.xml Thu Jul 12 23:43:00 2012
@@ -65,6 +65,9 @@ The <action> type attribute can be add,u
         <release version="3.2" date="TBA" description="
 TBA
         ">
+            <action issue="NET-465" dev="sebb" type="add" due-to="Bogdan Drozdowski">
+            FTPClient setSendBufferSize and setReceiveBufferSize on data socket.
+            </action>
             <action issue="NET-462" dev="sebb" type="add" due-to="Bogdan Drozdowski">
             FTPClient in PASSIVE_LOCAL_DATA_CONNECTION_MODE cannot work when host have several different IP.
             </action>

Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java?rev=1361003&r1=1361002&r2=1361003&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java Thu Jul 12 23:43:00 2012
@@ -592,7 +592,7 @@ implements Configurable
             return false;
         }
 
-        OutputStream output = new BufferedOutputStream(socket.getOutputStream(), getBufferSize());
+        OutputStream output = new BufferedOutputStream(socket.getOutputStream(), getDefaultedBufferSize());
 
         if (__fileType == ASCII_FILE_TYPE) {
             output = new ToNetASCIIOutputStream(output);
@@ -606,7 +606,7 @@ implements Configurable
         // Treat everything else as binary for now
         try
         {
-            Util.copyStream(local, output, getBufferSize(),
+            Util.copyStream(local, output, getDefaultedBufferSize(),
                     CopyStreamEvent.UNKNOWN_STREAM_SIZE, __mergeListeners(csl),
                     false);
         }
@@ -651,7 +651,7 @@ implements Configurable
             // own if they want to wrap the SocketOutputStream we return
             // for file types other than ASCII.
             output = new BufferedOutputStream(output,
-                    getBufferSize());
+                    getDefaultedBufferSize());
             output = new ToNetASCIIOutputStream(output);
 
         }
@@ -815,6 +815,11 @@ implements Configurable
             socket.setSoTimeout(__dataTimeout);
         }
 
+        if ( __bufferSize > 0 ) {
+            socket.setReceiveBufferSize(__bufferSize);
+            socket.setSendBufferSize(__bufferSize);
+        }
+
         return socket;
     }
 
@@ -1744,7 +1749,7 @@ implements Configurable
         }
 
         InputStream input = new BufferedInputStream(socket.getInputStream(),
-                getBufferSize());
+                getDefaultedBufferSize());
         if (__fileType == ASCII_FILE_TYPE) {
             input = new FromNetASCIIInputStream(input);
         }
@@ -1757,7 +1762,7 @@ implements Configurable
         // Treat everything else as binary for now
         try
         {
-            Util.copyStream(input, local, getBufferSize(),
+            Util.copyStream(input, local, getDefaultedBufferSize(),
                     CopyStreamEvent.UNKNOWN_STREAM_SIZE, __mergeListeners(csl),
                     false);
         } finally {
@@ -1823,7 +1828,7 @@ implements Configurable
             // own if they want to wrap the SocketInputStream we return
             // for file types other than ASCII.
             input = new BufferedInputStream(input,
-                    getBufferSize());
+                    getDefaultedBufferSize());
             input = new FromNetASCIIInputStream(input);
         }
         return new org.apache.commons.net.io.SocketInputStream(socket, input);
@@ -3309,22 +3314,29 @@ implements Configurable
 
 
     /**
-     * Set the internal buffer size.
+     * Set the internal buffer size for data sockets.
      *
-     * @param bufSize The size of the buffer
+     * @param bufSize The size of the buffer. Use a non-positive value to use the default.
      */
     public void setBufferSize(int bufSize) {
         __bufferSize = bufSize;
     }
 
     /**
-     * Retrieve the current internal buffer size.
+     * Retrieve the current internal buffer size for data sockets.
      * @return The current buffer size.
      */
     public int getBufferSize() {
         return __bufferSize;
     }
 
+    /**
+     * Get the buffer size, with default set to Util.DEFAULT_COPY_BUFFER_SIZE.
+     * @return the buffer size.
+     */
+    private int getDefaultedBufferSize() {
+        return __bufferSize > 0 ? __bufferSize : Util.DEFAULT_COPY_BUFFER_SIZE;
+    }
 
     /**
      * Implementation of the {@link Configurable Configurable} interface.