public static long copy(InputStream from,OutputStream to) throws IOException {
  Preconditions.checkNotNull(from);
  Preconditions.checkNotNull(to);
  byte[] buf=new byte[BUF_SIZE];
  long total=0;
  while (true) {
    int r=from.read(buf);
    if (r == -1) {
      break;
    }
    to.write(buf,0,r);
    total+=r;
  }
  return total;
}

public static long copy ( InputStream from , OutputStream to ) throws IOException { Preconditions . checkNotNull ( from ) ; Preconditions . checkNotNull ( to ) ; byte [ ] buf = new byte [ BUF_SIZE ] ; long total = 0 ; while ( true ) { int r = from . read ( buf ) ; if ( r == - 1 ) { break ; } to . write ( buf , 0 , r ) ; total += r ; } return total ; }
copies all bytes from the input stream to the output stream . does not close or flush either stream .
