question: 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 ) ; } }
target:  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.