# Class CompressionHeaderFactory

java.lang.Object
htsjdk.samtools.cram.build.CompressionHeaderFactory

public final class CompressionHeaderFactory extends Object
Factory for creating CRAM compression headers for containers when writing to a CRAM stream. The fixed data series are generally the same for every container in the stream (this is not required by the spec, but reflects the current htsjdk implementation), however, the tag data series and encodings can vary across containers based on which tags are present in the actual records for that container, and the best compressor to use based on the actual data. This class delegates to a `CRAMEncodingStrategy` object to determine which encodings to use for the fixed CRAM data series, and dynamically chooses the best encoding for tag data series.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`ALL_BYTES_USED`
`static final int`
`BYTE_SPACE_SIZE`

## Constructor Summary

Constructors
Constructor
Description
`CompressionHeaderFactory(CRAMEncodingStrategy encodingStrategy)`
Create a CompressionHeaderFactory using the provided CRAMEncodingStrategy.

## Method Summary

Modifier and Type
Method
Description
`CompressionHeader`
`createCompressionHeader(List<CRAMCompressionRecord> containerCRAMCompressionRecords, boolean coordinateSorted)`
Creates a compression header for the provided list of `CRAMCompressionRecord` objects.
`static htsjdk.samtools.cram.build.CompressionHeaderFactory.ByteSizeRange`
`getByteSizeRangeOfTagValues(List<CRAMCompressionRecord> records, int tagID)`
`CRAMEncodingStrategy`
`getEncodingStrategy()`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### BYTE_SPACE_SIZE

public static final int BYTE_SPACE_SIZE

See Also:
  - Constant Field Values

### ALL_BYTES_USED

public static final int ALL_BYTES_USED

See Also:
  - Constant Field Values

## Constructor Details

### CompressionHeaderFactory

public CompressionHeaderFactory(CRAMEncodingStrategy encodingStrategy)
Create a CompressionHeaderFactory using the provided CRAMEncodingStrategy.

Parameters:
  `encodingStrategy` - `CRAMEncodingStrategy` to use, may not be null

## Method Details

### createCompressionHeader

public CompressionHeader createCompressionHeader(List<CRAMCompressionRecord> containerCRAMCompressionRecords, boolean coordinateSorted)
Creates a compression header for the provided list of `CRAMCompressionRecord` objects. Resets any internal state (i.e. the tag encoding map state) as preparation for starting the next compression header.

Parameters:
  `containerCRAMCompressionRecords` - all CRAMRecords that will be stored in the container
  `coordinateSorted` - if true the records are assumed to be sorted by alignment position
Returns:
  `CompressionHeader` for the container for `containerCRAMRecords`

### getEncodingStrategy

public CRAMEncodingStrategy getEncodingStrategy()

### getByteSizeRangeOfTagValues

public static htsjdk.samtools.cram.build.CompressionHeaderFactory.ByteSizeRange getByteSizeRangeOfTagValues(List<CRAMCompressionRecord> records, int tagID)