private static ByteString readChunk(InputStream in,final int chunkSize) throws IOException {
  final byte[] buf=new byte[chunkSize];
  int bytesRead=0;
  while (bytesRead < chunkSize) {
    final int count=in.read(buf,bytesRead,chunkSize - bytesRead);
    if (count == -1) {
      break;
    }
    bytesRead+=count;
  }
  if (bytesRead == 0) {
    return null;
  }
 else {
    return ByteString.copyFrom(buf,0,bytesRead);
  }
}

private static ByteString readChunk ( InputStream in , final int chunkSize ) throws IOException { final byte [ ] buf = new byte [ chunkSize ] ; int bytesRead = 0 ; while ( bytesRead < chunkSize ) { final int count = in . read ( buf , bytesRead , chunkSize - bytesRead ) ; if ( count == - 1 ) { break ; } bytesRead += count ; } if ( bytesRead == 0 ) { return null ; } else { return ByteString . copyFrom ( buf , 0 , bytesRead ) ; } }
blocks until a chunk of the given size can be made from the stream , or eof is reached . calls read ( ) repeatedly in case the given stream implementation doesn ' t completely fill the given buffer in one read ( ) call .
