private boolean setUpNextChunk ( ) throws IOException { byte [ ] chunkData = new byte [ DEFAULT_CHUNK_SIZE ] ; int chunkSizeInBytes = 0 ; while ( chunkSizeInBytes < DEFAULT_CHUNK_SIZE ) { /** Read from the buffer of the decoded stream */ if ( null != decodedStreamBuffer && decodedStreamBuffer . hasNext ( ) ) { chunkData [ chunkSizeInBytes ++ ] = decodedStreamBuffer . next ( ) ; } /** Read from the wrapped stream */ else { int bytesToRead = DEFAULT_CHUNK_SIZE - chunkSizeInBytes ; int count = is . read ( chunkData , chunkSizeInBytes , bytesToRead ) ; if ( count != - 1 ) { if ( null != decodedStreamBuffer ) decodedStreamBuffer . buffer ( chunkData , chunkSizeInBytes , count ) ; chunkSizeInBytes += count ; } else break ; } } if ( chunkSizeInBytes == 0 ) { byte [ ] signedFinalChunk = createSignedChunk ( FINAL_CHUNK ) ; currentChunkIterator = new ChunkContentIterator ( signedFinalChunk ) ; return true ; } else { if ( chunkSizeInBytes < chunkData . length ) { chunkData = Arrays . copyOf ( chunkData , chunkSizeInBytes ) ; } byte [ ] signedChunkContent = createSignedChunk ( chunkData ) ; currentChunkIterator = new ChunkContentIterator ( signedChunkContent ) ; return false ; } }
Read in the next chunk of data and create the necessary chunk extensions .