You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by df...@apache.org on 2004/09/08 19:14:47 UTC

cvs commit: jakarta-commons/net/src/java/org/apache/commons/net/io Util.java

dfs         2004/09/08 10:14:46

  Modified:    net/src/java/org/apache/commons/net/ftp FTPClient.java
               net/src/java/org/apache/commons/net/io Util.java
  Log:
  Added a version of io.Util.copyStream that lets you specify whether or
  not to flush the output stream.  Changed FTPClient retrieveFile and
  __storeFile to not flush.
  
  Revision  Changes    Path
  1.39      +7 -2      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.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- FTPClient.java	29 Jun 2004 04:54:30 -0000	1.38
  +++ FTPClient.java	8 Sep 2004 17:14:46 -0000	1.39
  @@ -25,6 +25,7 @@
   import java.net.ServerSocket;
   import java.net.Socket;
   import java.util.Vector;
  +import org.apache.commons.net.io.CopyStreamEvent;
   import org.apache.commons.net.io.FromNetASCIIInputStream;
   import org.apache.commons.net.io.ToNetASCIIOutputStream;
   import org.apache.commons.net.io.Util;
  @@ -370,7 +371,9 @@
           // Treat everything else as binary for now
           try
           {
  -            Util.copyStream(local, output);
  +            Util.copyStream(local, output, Util.DEFAULT_COPY_BUFFER_SIZE,
  +                            CopyStreamEvent.UNKNOWN_STREAM_SIZE, null,
  +                            false);
           }
           catch (IOException e)
           {
  @@ -1266,7 +1269,9 @@
           // Treat everything else as binary for now
           try
           {
  -            Util.copyStream(input, local);
  +            Util.copyStream(input, local, Util.DEFAULT_COPY_BUFFER_SIZE,
  +                            CopyStreamEvent.UNKNOWN_STREAM_SIZE, null,
  +                            false);
           }
           catch (IOException e)
           {
  
  
  
  1.12      +49 -2     jakarta-commons/net/src/java/org/apache/commons/net/io/Util.java
  
  Index: Util.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/io/Util.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Util.java	29 Jun 2004 04:54:31 -0000	1.11
  +++ Util.java	8 Sep 2004 17:14:46 -0000	1.12
  @@ -67,6 +67,10 @@
        *          Should be set to CopyStreamEvent.UNKNOWN_STREAM_SIZE if unknown.
        * @param listener  The CopyStreamListener to notify of progress.  If
        *      this parameter is null, notification is not attempted.
  +     * @param flush Whether to flush the output stream after every
  +     *        write.  This is necessary for interactive sessions that rely on
  +     *        buffered streams.  If you don't flush, the data will stay in
  +     *        the stream buffer.
        * @exception CopyStreamException  If an error occurs while reading from the
        *            source or writing to the destination.  The CopyStreamException
        *            will contain the number of bytes confirmed to have been
  @@ -78,7 +82,8 @@
        ***/
       public static final long copyStream(InputStream source, OutputStream dest,
                                           int bufferSize, long streamSize,
  -                                        CopyStreamListener listener)
  +                                        CopyStreamListener listener,
  +                                        boolean flush)
       throws CopyStreamException
       {
           int bytes;
  @@ -101,7 +106,8 @@
                       if (bytes < 0)
                           break;
                       dest.write(bytes);
  -                    dest.flush();
  +                    if(flush)
  +                      dest.flush();
                       ++total;
                       if (listener != null)
                           listener.bytesTransferred(total, 1, streamSize);
  @@ -122,6 +128,47 @@
           }
   
           return total;
  +    }
  +
  +
  +    /***
  +     * Copies the contents of an InputStream to an OutputStream using a
  +     * copy buffer of a given size and notifies the provided
  +     * CopyStreamListener of the progress of the copy operation by calling
  +     * its bytesTransferred(long, int) method after each write to the
  +     * destination.  If you wish to notify more than one listener you should
  +     * use a CopyStreamAdapter as the listener and register the additional
  +     * listeners with the CopyStreamAdapter.
  +     * <p>
  +     * The contents of the InputStream are
  +     * read until the end of the stream is reached, but neither the
  +     * source nor the destination are closed.  You must do this yourself
  +     * outside of the method call.  The number of bytes read/written is
  +     * returned.
  +     * <p>
  +     * @param source  The source InputStream.
  +     * @param dest    The destination OutputStream.
  +     * @param bufferSize  The number of bytes to buffer during the copy.
  +     * @param streamSize  The number of bytes in the stream being copied.
  +     *          Should be set to CopyStreamEvent.UNKNOWN_STREAM_SIZE if unknown.
  +     * @param listener  The CopyStreamListener to notify of progress.  If
  +     *      this parameter is null, notification is not attempted.
  +     * @exception CopyStreamException  If an error occurs while reading from the
  +     *            source or writing to the destination.  The CopyStreamException
  +     *            will contain the number of bytes confirmed to have been
  +     *            transferred before an
  +     *            IOException occurred, and it will also contain the IOException
  +     *            that caused the error.  These values can be retrieved with
  +     *            the CopyStreamException getTotalBytesTransferred() and
  +     *            getIOException() methods.
  +     ***/
  +    public static final long copyStream(InputStream source, OutputStream dest,
  +                                        int bufferSize, long streamSize,
  +                                        CopyStreamListener listener)
  +    throws CopyStreamException
  +    {
  +      return copyStream(source, dest, bufferSize, streamSize, listener,
  +                        true);
       }
   
   
  
  
  

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