public static long copyStream(InputStream in,OutputStream out) throws IOException {
  Reject.ifNull(in,out);
  final byte[] buffer=new byte[BUFFER_SIZE];
  long bytesCopied=0L;
  for (int bytesRead=in.read(buffer); bytesRead != -1; bytesRead=in.read(buffer)) {
    out.write(buffer,0,bytesRead);
    bytesCopied+=bytesRead;
  }
  return bytesCopied;
}

public static long copyStream ( InputStream in , OutputStream out ) throws IOException { Reject . ifNull ( in , out ) ; final byte [ ] buffer = new byte [ BUFFER_SIZE ] ; long bytesCopied = 0L ; for ( int bytesRead = in . read ( buffer ) ; bytesRead != - 1 ; bytesRead = in . read ( buffer ) ) { out . write ( buffer , 0 , bytesRead ) ; bytesCopied += bytesRead ; } return bytesCopied ; }
copies the whole input stream to the given output stream . neither stream is closed after the copy .
