code: public static long copy(
                      final InputStream  input,
                      final OutputStream output
                      )
      throws IOException
      {
          _LOG_.debug( "begin copy" );
  
  
          @SuppressWarnings( "resource" )
          BufferedInputStream  b_input = (BufferedInputStream.class.isInstance( input )
                                          ? BufferedInputStream.class.cast( input )
                                          : new BufferedInputStream( input ));
          @SuppressWarnings( "resource" )
          BufferedOutputStream  b_output = (BufferedOutputStream.class.isInstance( output )
                                          ? BufferedOutputStream.class.cast( output )
                                          : new BufferedOutputStream( output ));
  
          byte[]  buffer = new byte[512];
          long  size = 0;
          try {
              while (true) {
                  int  n = b_input.read( buffer );
                                   //@throws IOException
                  if (n == -1) {
                      break;
                  }
                  b_output.write( buffer, 0, n );
                       //@throws IOException
                  size += n;
              }
          } finally {
              try {
                  b_output.flush();
              } catch (Exception ex) {
                  //ignorable
              }
          }
  
          _LOG_.debug( "end copy: #bytes=" + size );
          return size;
      }
docs: Reads the contents from the specified input stream and writes them to the output stream.
  In this method, the given streams are not closed.
  
  @param   input
  the input stream.
  @param   output
  the output stream.
  @return
  the total number of bytes written to the output.