Class GzipBlockStream

java.lang.Object
io.datarouter.bytes.compress.gzip.GzipBlockStream

public class GzipBlockStream extends Object
Gzip normally encodes and decodes in a single thread which underutilizes multi-threaded hardware. The data must be written to a single OutputStream and read from a single InputStream which is not parallelizable. Alternatively we can split the data into blocks and run the gzip encoding on each block in separate threads. This class splits the incoming bytes into blocks and gzips each block independently. Small tokens can be combined into GzipBlockStreamRow objects, where each row will be fully owned by one block. When writing, it prepends a block length header before writing each gzipped data block. When reading, the main thread can pull gzipped blocks from the InputStream and pass them to other threads to decode. Besides un-gzipping, blocks can further decoded in helper threads. Note that this is not compatible with the normal Gzip file format.