public static long copy(InputStream in,OutputStream out,long length) throws IOException {
  try {
    long copied=0;
    int len=(int)Math.min(length,Constants.IO_BUFFER_SIZE);
    byte[] buffer=new byte[len];
    while (length > 0) {
      len=in.read(buffer,0,len);
      if (len < 0) {
        break;
      }
      if (out != null) {
        out.write(buffer,0,len);
      }
      copied+=len;
      length-=len;
      len=(int)Math.min(length,Constants.IO_BUFFER_SIZE);
    }
    return copied;
  }
 catch (  Exception e) {
    throw DbException.convertToIOException(e);
  }
}

public static long copy ( InputStream in , OutputStream out , long length ) throws IOException { try { long copied = 0 ; int len = ( int ) Math . min ( length , Constants . IO_BUFFER_SIZE ) ; byte [ ] buffer = new byte [ len ] ; while ( length > 0 ) { len = in . read ( buffer , 0 , len ) ; if ( len < 0 ) { break ; } if ( out != null ) { out . write ( buffer , 0 , len ) ; } copied += len ; length -= len ; len = ( int ) Math . min ( length , Constants . IO_BUFFER_SIZE ) ; } return copied ; } catch ( Exception e ) { throw DbException . convertToIOException ( e ) ; } }
copy all data from the input stream to the output stream . both streams are kept open .
