src/main/java/org/jboss/util/stream/Streams.java
/**
    * Copy a limited number of bytes from the input stream to the 
    * output stream.
    *
    * @param input   Stream to read bytes from.
    * @param output  Stream to write bytes to.
    * @param buffer  The buffer to use while copying.
    * @param length  The maximum number of bytes to copy.
    * @return        The total number of bytes copied.
    *
    * @throws IOException  Failed to copy bytes.
    */
Copy a limited number of bytes from the input stream to the
output stream.

@param input   Stream to read bytes from.
@param output  Stream to write bytes to.
@param buffer  The buffer to use while copying.
@param length  The maximum number of bytes to copy.
@return        The total number of bytes copied.

@throws IOException  Failed to copy bytes.
Copy a limited number of bytes from the input stream to the output stream . @param input Stream to read bytes from . @param output Stream to write bytes to . @param buffer The buffer to use while copying . @param length The maximum number of bytes to copy . @return The total number of bytes copied . @throws IOException Failed to copy bytes .
public static long copySome(final InputStream input, 
                               final OutputStream output, 
                               final byte buffer[],
                               final long length)
      throws IOException
   {
      long total = 0;
      int read;
      int readLength;
      boolean trace = log.isTraceEnabled();
      readLength = Math.min((int)length, buffer.length);
      if (trace) {
         log.trace("initial read length: " + readLength);
      }
      while (readLength != 0 && (read = input.read(buffer, 0, readLength)) != -1) 
      {
         if (trace) log.trace("read bytes: " + read);
         output.write(buffer, 0, read);
         total += read;
         if (trace) log.trace("total bytes read: " + total);
         readLength = Math.min((int)(length - total), buffer.length);
         if (trace) log.trace("next read length: " + readLength);
      }
      return total;
   }
public static long copySome ( final InputStream input , final OutputStream output , final byte buffer [ ] , final long length ) throws IOException { long total = 0 ; int read ; int readLength ; boolean trace = log . isTraceEnabled ( ) ; readLength = Math . min ( ( int ) length , buffer . length ) ; if ( trace ) { log . trace ( "initial read length: " + readLength ) ; } while ( readLength != 0 && ( read = input . read ( buffer , 0 , readLength ) ) != - 1 ) { if ( trace ) log . trace ( "read bytes: " + read ) ; output . write ( buffer , 0 , read ) ; total += read ; if ( trace ) log . trace ( "total bytes read: " + total ) ; readLength = Math . min ( ( int ) ( length - total ) , buffer . length ) ; if ( trace ) log . trace ( "next read length: " + readLength ) ; } return total ; }
Copy a limited number of bytes from the input stream to the
 output stream.
Copy a limited number of bytes from the input stream to the output stream .
// setup the initial readLength, if length is less than the buffer // size, then we only want to read that much // update the readLength