static int copyBytes(OutputStream os,InputStream is,byte[] ioBuffer,int maxSize) throws IOException {
  int totalSize=0;
  while (totalSize < maxSize) {
    int rc=is.read(ioBuffer,0,Math.min(maxSize - totalSize,ioBuffer.length));
    if (rc == -1) {
      break;
    }
    os.write(ioBuffer,0,rc);
    totalSize+=rc;
  }
  return totalSize;
}

static int copyBytes ( OutputStream os , InputStream is , byte [ ] ioBuffer , int maxSize ) throws IOException { int totalSize = 0 ; while ( totalSize < maxSize ) { int rc = is . read ( ioBuffer , 0 , Math . min ( maxSize - totalSize , ioBuffer . length ) ) ; if ( rc == - 1 ) { break ; } os . write ( ioBuffer , 0 , rc ) ; totalSize += rc ; } return totalSize ; }
pumps all the bytes ( but no more that maxsize ) from given input stream through iobuffer to given output stream and returns number of moved bytes .
