-
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
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/main/java/htsjdk/tribble/index/tabix/StreamBasedTabixIndexCreator.java
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,55 @@ | ||
package htsjdk.tribble.index.tabix; | ||
|
||
import htsjdk.samtools.BinningIndexContent; | ||
import htsjdk.samtools.SAMSequenceDictionary; | ||
import htsjdk.samtools.util.BlockCompressedOutputStream; | ||
import htsjdk.tribble.index.Index; | ||
import htsjdk.tribble.util.LittleEndianOutputStream; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
public class StreamBasedTabixIndexCreator extends TabixIndexCreator { | ||
|
||
static class StreamBasedTabixIndex extends TabixIndex { | ||
private final OutputStream out; | ||
|
||
StreamBasedTabixIndex( | ||
TabixFormat formatSpec, | ||
List<String> sequenceNames, | ||
BinningIndexContent[] indices, | ||
OutputStream out) { | ||
super(formatSpec, sequenceNames, indices); | ||
this.out = out; | ||
} | ||
|
||
@Override | ||
public void writeBasedOnFeaturePath(final Path featurePath) throws IOException { | ||
try (final LittleEndianOutputStream los = | ||
new LittleEndianOutputStream(new BlockCompressedOutputStream(out, (Path) null))) { | ||
write(los); | ||
} | ||
} | ||
} | ||
|
||
private final OutputStream out; | ||
|
||
public StreamBasedTabixIndexCreator( | ||
SAMSequenceDictionary sequenceDictionary, TabixFormat formatSpec, OutputStream out) { | ||
super(sequenceDictionary, formatSpec); | ||
this.out = out; | ||
} | ||
|
||
@Override | ||
public Index finalizeIndex(long finalFilePosition) { | ||
Index index = super.finalizeIndex(finalFilePosition); | ||
TabixIndex tabixIndex = (TabixIndex) index; | ||
return new StreamBasedTabixIndex( | ||
tabixIndex.getFormatSpec(), | ||
tabixIndex.getSequenceNames(), | ||
tabixIndex.getIndices(), | ||
out); | ||
} | ||
} |