# Class IndexMerger<T>

java.lang.Object
htsjdk.samtools.IndexMerger<T>

Type Parameters:
  `T` - the type of the index (e.g. `AbstractBAMFileIndex` for a BAM index).

Direct Known Subclasses:
  `BAMIndexMerger, CRAIIndexMerger, SBIIndexMerger, TabixIndexMerger`

public abstract class IndexMerger<T> extends Object
Merges index files for (headerless) parts of a partitioned main file into a single index file. The file and directory structure for the partitioned file is defined in subclasses, but the general pattern is as follows. A partitioned file (e.g BAM, CRAM, or VCF) is a directory containing the following files:

1. A file named header containing all header bytes.
2. Zero or more files named part-00000, part-00001, ... etc, containing file records, with no header.
3. A file named terminator containing a file terminator. (This may be absent if it is not required by the format.)

For indexing, an index file is generated for each (headerless) part file. These files should be named .part-00000.ext, .part-00001.ext, ... etc, where .ext is the usual index extension, e.g. .bai for a BAM index. Note the leading . to make the files hidden. This class will merge all the indexes for the parts files into a single index file.

## Field Summary

Fields
Modifier and Type
Field
Description
`protected final OutputStream`
`out`
`protected final List<Long>`
`partLengths`

## Constructor Summary

Constructors
Constructor
Description
`IndexMerger(OutputStream out, long headerLength)`
Create an index merger.

## Method Summary

Modifier and Type
Method
Description
`abstract void`
`finish(long dataFileLength)`
Finish merging the indexes, and close the output stream.
`abstract void`
`processIndex(T index, long partLength)`
Process the next index and add to the merged index.

### Methods inherited from class Object

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

## Field Details

### out

protected final OutputStream out

### partLengths

protected final List<Long> partLengths

## Constructor Details

### IndexMerger

public IndexMerger(OutputStream out, long headerLength)
Create an index merger.

Parameters:
  `out` - the output stream to write the merged index to. Must be uncompressed since the implementation of this class will provide appropriate compression.
  `headerLength` - the length of the header file, in bytes.

## Method Details

### processIndex

public abstract void processIndex(T index, long partLength)
Process the next index and add to the merged index.

Parameters:
  `index` - the index to merge
  `partLength` - the length of the part file corresponding to the index, in bytes.

### finish

public abstract void finish(long dataFileLength) throws IOException
Finish merging the indexes, and close the output stream.

Parameters:
  `dataFileLength` - the length of the total data file, in bytes.
Throws:
  `IOException` - if an error occurs