# Class VCFEncoder

java.lang.Object
htsjdk.beta.codecs.variants.vcf.VCFEncoder

All Implemented Interfaces:
  `HtsEncoder<VCFHeader, VariantContext>, VariantsEncoder, Closeable, AutoCloseable`

Direct Known Subclasses:
  `VCFEncoderV3_2, VCFEncoderV3_3, VCFEncoderV4_0, VCFEncoderV4_1, VCFEncoderV4_2`

@InternalAPI public abstract class VCFEncoder extends Object implements VariantsEncoder
InternalAPI Base class for concrete implementations of `HtsContentType.VARIANT_CONTEXTS` encoders.

## Constructor Summary

Constructors
Constructor
Description
`VCFEncoder(Bundle outputBundle, VariantsEncoderOptions variantsEncoderOptions)`
InternalAPI Create a new VCF encoder from a `Bundle`.

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Close any resources associated with this decoder.
`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.
`VariantsEncoderOptions`
`getVariantsEncoderOptions()`
Get the `VariantsEncoderOptions` for this encoder.
`void`
`setHeader(VCFHeader vcfHeader)`
Set the file format header for this decoder, of type `H`.
`void`
`write(VariantContext variantContext)`
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

### VCFEncoder

@InternalAPI public VCFEncoder(Bundle outputBundle, VariantsEncoderOptions variantsEncoderOptions)
InternalAPI Create a new VCF encoder from a `Bundle`. NOTE: callers that provide an output stream resource should provide a buffered output stream if buffering is desired, since the encoder does not provide an additional buffering layer.

Parameters:
  `outputBundle` - the output `Bundle` to encode
  `variantsEncoderOptions` - the `VariantsEncoderOptions` 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<VCFHeader, VariantContext>`
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<VCFHeader, VariantContext>`
Returns:
  a user-friendly display name for this encoder for use in error and warning messages

### setHeader

public void setHeader(VCFHeader vcfHeader)
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<VCFHeader, VariantContext>`
Parameters:
  `vcfHeader` - to use

### write

public void write(VariantContext variantContext)
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<VCFHeader, VariantContext>`
Parameters:
  `variantContext` - 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<VCFHeader, VariantContext>`

### getOutputBundle

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

Returns:
  the output `Bundle` for this encoder

### getVariantsEncoderOptions

public VariantsEncoderOptions getVariantsEncoderOptions()
Get the `VariantsEncoderOptions` for this encoder.

Returns:
  the `VariantsEncoderOptions` for this encoder.