Class GzipCodec
java.lang.Object
htsjdk.samtools.util.GzipCodec
A reusable codec for compressing and decompressing GZIP and BGZF data using direct
Deflater/Inflater operations on ByteBuffers. Designed to be
allocated once and reused across many compress/decompress operations.
Supports two output formats for compression:
GzipCodec.Format.GZIP— standard 10-byte GZIP header (RFC 1952)GzipCodec.Format.BGZF— BGZF header with BC extra subfield (SAM/BAM spec)
Decompression handles both formats transparently by parsing the FLG byte and skipping any optional GZIP fields.
Not thread-safe. Use one instance per thread.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCreate a codec with the default compression level and default strategy.GzipCodec(int compressionLevel) Create a codec with the specified compression level and default strategy.GzipCodec(int compressionLevel, int deflateStrategy) Create a codec with the specified compression level and deflate strategy.GzipCodec(int compressionLevel, int deflateStrategy, DeflaterFactory deflaterFactory, InflaterFactory inflaterFactory) Create a codec with full control over compression parameters and factory implementations. -
Method Summary
Modifier and TypeMethodDescriptioncompress(ByteBuffer input) Compress data and return a new ByteBuffer containing the compressed result.compress(ByteBuffer input, GzipCodec.Format format) Compress data and return a new ByteBuffer containing the compressed result.intcompress(ByteBuffer input, ByteBuffer output) Compress data frominputintooutputusing standard GZIP format.intcompress(ByteBuffer input, ByteBuffer output, GzipCodec.Format format) Compress data frominputintooutputusing the specified format.decompress(ByteBuffer input) Decompress GZIP or BGZF data and return a new ByteBuffer containing the result.intdecompress(ByteBuffer input, ByteBuffer output) Decompress GZIP or BGZF data frominputintooutput.voidsetCheckCrcs(boolean check) Enable or disable CRC32 validation during decompression.
-
Constructor Details
-
GzipCodec
public GzipCodec()Create a codec with the default compression level and default strategy. -
GzipCodec
public GzipCodec(int compressionLevel) Create a codec with the specified compression level and default strategy. -
GzipCodec
public GzipCodec(int compressionLevel, int deflateStrategy) Create a codec with the specified compression level and deflate strategy. -
GzipCodec
public GzipCodec(int compressionLevel, int deflateStrategy, DeflaterFactory deflaterFactory, InflaterFactory inflaterFactory) Create a codec with full control over compression parameters and factory implementations.- Parameters:
compressionLevel- deflate compression level (0-9)deflateStrategy- deflate strategy (e.g.,Deflater.DEFAULT_STRATEGY,Deflater.FILTERED)deflaterFactory- factory for creating Deflater instancesinflaterFactory- factory for creating Inflater instances
-
-
Method Details
-
setCheckCrcs
public void setCheckCrcs(boolean check) Enable or disable CRC32 validation during decompression. -
compress
Compress data frominputintooutputusing standard GZIP format.- Parameters:
input- data to compress (from position to limit; position is advanced to limit)output- buffer to write compressed data into (from position; position is advanced)- Returns:
- number of bytes written to output
-
compress
Compress data frominputintooutputusing the specified format.- Parameters:
input- data to compress (from position to limit; position is advanced to limit)output- buffer to write compressed data into (from position; position is advanced)format- the output format (GzipCodec.Format.GZIPorGzipCodec.Format.BGZF)- Returns:
- number of bytes written to output
-
compress
Compress data and return a new ByteBuffer containing the compressed result.- Parameters:
input- data to compress (from position to limit; position is advanced to limit)- Returns:
- a new ByteBuffer containing the compressed data, positioned at 0 with limit at the end
-
compress
Compress data and return a new ByteBuffer containing the compressed result.- Parameters:
input- data to compress (from position to limit; position is advanced to limit)format- the output format- Returns:
- a new ByteBuffer containing the compressed data, positioned at 0 with limit at the end
-
decompress
Decompress GZIP or BGZF data frominputintooutput. Handles both standard GZIP and BGZF transparently.- Parameters:
input- compressed data (from position to limit; position is advanced)output- buffer to write decompressed data into (from position; position is advanced)- Returns:
- number of decompressed bytes written to output
-
decompress
Decompress GZIP or BGZF data and return a new ByteBuffer containing the result. Reads the ISIZE field from the GZIP trailer to determine the output size.- Parameters:
input- compressed data (from position to limit; position is advanced)- Returns:
- a new ByteBuffer containing the decompressed data, positioned at 0 with limit at the end
-