# Class ExternalCompressor

java.lang.Object
htsjdk.samtools.cram.compression.ExternalCompressor

Direct Known Subclasses:
  `BZIP2ExternalCompressor, FQZCompExternalCompressor, GZIPExternalCompressor, LZMAExternalCompressor, NameTokeniserExternalCompressor, RangeExternalCompressor, RANS4x8ExternalCompressor, RANSNx16ExternalCompressor, RAWExternalCompressor, TrialCompressor`

public abstract class ExternalCompressor extends Object
Abstract base class for CRAM external block compressors. Each subclass wraps a specific compression algorithm (GZIP, rANS, BZIP2, etc.) and provides compress/uncompress operations on raw byte arrays. Instances are typically obtained via `getCompressorForMethod(BlockCompressionMethod, int)`.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`NO_COMPRESSION_ARG`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`ExternalCompressor(BlockCompressionMethod method)`

## Method Summary

Modifier and Type
Method
Description
`abstract byte[]`
`compress(byte[] data, CRAMCodecModelContext contextModel)`
Compress the data using the codec-specific context model.
`boolean`
`equals(Object o)`
`static ExternalCompressor`
`getCompressorForMethod(BlockCompressionMethod compressionMethod, int compressorSpecificArg)`
Return an ExternalCompressor subclass based on the BlockCompressionMethod.
`BlockCompressionMethod`
`getMethod()`
`int`
`hashCode()`
`protected void`
`setMethod(BlockCompressionMethod method)`
Set the compression method.
`String`
`toString()`
`abstract byte[]`
`uncompress(byte[] data)`
Decompress the data.

### Methods inherited from class Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Field Details

### NO_COMPRESSION_ARG

public static final int NO_COMPRESSION_ARG

See Also:
  - Constant Field Values

## Constructor Details

### ExternalCompressor

protected ExternalCompressor(BlockCompressionMethod method)

Parameters:
  `method` - the compression method for this compressor, or null if the method will be determined later (e.g., by `TrialCompressor` after its first trial)

## Method Details

### setMethod

protected void setMethod(BlockCompressionMethod method)
Set the compression method. For use by subclasses like `TrialCompressor` that determine their method after construction.

Parameters:
  `method` - the compression method to set

### compress

public abstract byte[] compress(byte[] data, CRAMCodecModelContext contextModel)
Compress the data using the codec-specific context model.

Parameters:
  `data` - the data to compress
  `contextModel` - the context model to use for compression; may be null
Returns:
  the compressed data

### uncompress

public abstract byte[] uncompress(byte[] data)
Decompress the data.

Parameters:
  `data` - the compressed data
Returns:
  the decompressed data

### getMethod

public BlockCompressionMethod getMethod()

Returns:
  the compression method used by this compressor
Throws:
  `IllegalStateException` - if the method has not been determined yet (compress() must be called first for compressors like `TrialCompressor`)

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### equals

public boolean equals(Object o)

Overrides:
  `equals` in class `Object`

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### getCompressorForMethod

public static ExternalCompressor getCompressorForMethod(BlockCompressionMethod compressionMethod, int compressorSpecificArg)
Return an ExternalCompressor subclass based on the BlockCompressionMethod. Compressor-specific arguments must be populated by the caller.

Parameters:
  `compressionMethod` - the type of compressor required (`BlockCompressionMethod`)
  `compressorSpecificArg` - the required order for RANS compressors; or the desired write compression level for GZIP
Returns:
  an ExternalCompressor of the requested type, populated with an compressor-specific args