-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package htsjdk.samtools.cram; | ||
|
||
import htsjdk.samtools.IndexMerger; | ||
|
||
import java.io.BufferedOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.zip.GZIPOutputStream; | ||
|
||
public class CRAIIndexMerger extends IndexMerger<CRAIIndex> { | ||
|
||
private GZIPOutputStream compressedOut; | ||
private long offset; | ||
|
||
public CRAIIndexMerger(final OutputStream out, final long headerLength) throws IOException { | ||
super(out, headerLength); | ||
this.compressedOut = new GZIPOutputStream(new BufferedOutputStream(out)); | ||
this.offset = headerLength; | ||
} | ||
|
||
@Override | ||
public void processIndex(CRAIIndex index, long partLength) { | ||
index.getCRAIEntries() | ||
.forEach(e -> shift(e, offset).writeToStream(compressedOut)); | ||
offset += partLength; | ||
} | ||
|
||
private static CRAIEntry shift(CRAIEntry entry, long offset) { | ||
return new CRAIEntry(entry.getSequenceId(), entry.getAlignmentStart(), entry.getAlignmentSpan(), entry.getContainerStartByteOffset() + offset, entry.getSliceByteOffsetFromCompressionHeaderStart(), entry.getSliceByteSize()); | ||
} | ||
|
||
@Override | ||
public void finish(long dataFileLength) throws IOException { | ||
compressedOut.flush(); | ||
compressedOut.close(); | ||
} | ||
} |