# Class CRAMEncoder

java.lang.Object
htsjdk.beta.codecs.reads.cram.CRAMEncoder

All Implemented Interfaces:
  `HtsEncoder<SAMFileHeader, SAMRecord>, ReadsEncoder, Closeable, AutoCloseable`

Direct Known Subclasses:
  `CRAMEncoderV2_1, CRAMEncoderV3_0, CRAMEncoderV3_1`

@InternalAPI public abstract class CRAMEncoder extends Object implements ReadsEncoder
InternalAPI Base class for `BundleResourceType.FMT_READS_CRAM` decoders.

## Constructor Summary

Constructors
Constructor
Description
`CRAMEncoder(Bundle outputBundle, ReadsEncoderOptions readsEncoderOptions)`
InternalAPI Create a CRAM encoder for the given output bundle.

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Close any resources associated with this decoder.
`static CRAMReferenceSource`
`getCRAMReferenceSource(CRAMEncoderOptions cramEncoderOptions)`
Return a `CRAMReferenceSource` using the `ReadsEncoderOptions`, or a default source.
`final String`
`getDisplayName()`
Get a user-friendly display name for this encoder.
`final String`
`getFileFormat()`
Get the name of the file format supported by this encoder.
`Bundle`
`getOutputBundle()`
Get the output `Bundle` for this encoder.
`ReadsEncoderOptions`
`getReadsEncoderOptions()`
Get the `ReadsEncoderOptions` for this encoder.
`void`
`setHeader(SAMFileHeader samFileHeader)`
Set the file format header for this decoder, of type `H`.
`void`
`write(SAMRecord record)`
Write a single record to the underlying output.

### Methods inherited from class Object

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

### Methods inherited from interface HtsEncoder

`getVersion`

## Constructor Details

### CRAMEncoder

@InternalAPI public CRAMEncoder(Bundle outputBundle, ReadsEncoderOptions readsEncoderOptions)
InternalAPI Create a CRAM encoder for the given output bundle. The primary resource in the bundle must have content type `BundleResourceType.CT_ALIGNED_READS` (to find a decoder for a bundle, see `ReadsResolver`).

Parameters:
  `outputBundle` - bundle to encode
  `readsEncoderOptions` - options to use

## Method Details

### getFileFormat

public final String getFileFormat()
Description copied from interface: `HtsEncoder`
Get the name of the file format supported by this encoder. The format name defines the underlying format handled by this encoder, and also corresponds to the format of the primary bundle resource that is required when encoding (see `BundleResourceType` and `BundleResource.getFileFormat()`).

Specified by:
  `getFileFormat` in interface `HtsEncoder<SAMFileHeader, SAMRecord>`
Returns:
  the name of the underlying file format handled by this encoder

### getDisplayName

public final String getDisplayName()
Description copied from interface: `HtsEncoder`
Get a user-friendly display name for this encoder.

Specified by:
  `getDisplayName` in interface `HtsEncoder<SAMFileHeader, SAMRecord>`
Returns:
  a user-friendly display name for this encoder for use in error and warning messages

### setHeader

public void setHeader(SAMFileHeader samFileHeader)
Description copied from interface: `HtsEncoder`
Set the file format header for this decoder, of type `H`. `HtsEncoder.setHeader(HtsHeader)` must be called before `HtsEncoder.write(HtsRecord)` can be called.

Specified by:
  `setHeader` in interface `HtsEncoder<SAMFileHeader, SAMRecord>`
Parameters:
  `samFileHeader` - to use

### write

public void write(SAMRecord record)
Description copied from interface: `HtsEncoder`
Write a single record to the underlying output. `HtsEncoder.write(HtsRecord)` may only called after `HtsEncoder.setHeader(HtsHeader)` has been called.

Specified by:
  `write` in interface `HtsEncoder<SAMFileHeader, SAMRecord>`
Parameters:
  `record` - record to write

### close

public void close()
Description copied from interface: `HtsEncoder`
Close any resources associated with this decoder.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `HtsEncoder<SAMFileHeader, SAMRecord>`

### getOutputBundle

public Bundle getOutputBundle()
Get the output `Bundle` for this encoder.

Returns:
  the output `Bundle` for this encoder

### getReadsEncoderOptions

public ReadsEncoderOptions getReadsEncoderOptions()
Get the `ReadsEncoderOptions` for this encoder.

Returns:
  the `ReadsEncoderOptions` for this encoder.

### getCRAMReferenceSource

@InternalAPI public static CRAMReferenceSource getCRAMReferenceSource(CRAMEncoderOptions cramEncoderOptions)
Return a `CRAMReferenceSource` using the `ReadsEncoderOptions`, or a default source.

Parameters:
  `cramEncoderOptions` - CRAMEncoderOptions options to use
Returns:
  a `CRAMReferenceSource`