diff --git a/src/main/java/htsjdk/tribble/writer/FeatureWriterFactory.java b/src/main/java/htsjdk/tribble/writer/FeatureWriterFactory.java index 7b8cc9c819..1613a838a2 100644 --- a/src/main/java/htsjdk/tribble/writer/FeatureWriterFactory.java +++ b/src/main/java/htsjdk/tribble/writer/FeatureWriterFactory.java @@ -186,18 +186,16 @@ public FeatureWriter makeWriter(final String outputFileNa } final IndexCreator idxCreator; - final String indexFile; + final Path indexPath; if (blockCompressed) { idxCreator = new TabixIndexCreator(seqDict, encoder.getTabixFormat()); - indexFile = Tribble.tabixIndexFile(outputFileName); + indexPath = Tribble.tabixIndexPath(outputPath); } else { - // TODO: https://github.com/samtools/htsjdk/pull/810 - // TODO: the dynamic index should use the corresponding Path constructor - idxCreator = new DynamicIndexCreator(outputPath.toFile(), iba); - indexFile = Tribble.indexFile(outputFileName); + idxCreator = new DynamicIndexCreator(outputPath, iba); + indexPath = Tribble.indexPath(outputPath); } - return maybeAsync(new IndexingFeatureWriter<>(encoder, outputStream, idxCreator, indexFile, seqDict)); + return maybeAsync(new IndexingFeatureWriter<>(encoder, outputStream, idxCreator, indexPath, seqDict)); } catch (final IOException e) { throw new TribbleException("Unable to create writer for " + outputFileName, e); diff --git a/src/main/java/htsjdk/tribble/writer/IndexingFeatureWriter.java b/src/main/java/htsjdk/tribble/writer/IndexingFeatureWriter.java index a15988e0e6..9ef89ae193 100644 --- a/src/main/java/htsjdk/tribble/writer/IndexingFeatureWriter.java +++ b/src/main/java/htsjdk/tribble/writer/IndexingFeatureWriter.java @@ -39,6 +39,7 @@ import java.io.IOException; import java.io.OutputStream; import java.nio.file.Files; +import java.nio.file.Path; /** * Feature writer class for indexing on the fly. @@ -51,7 +52,7 @@ final class IndexingFeatureWriter extends FeatureWriterImpl extends FeatureWriterImpl encoder, final OutputStream outputStream, - final IndexCreator idxCreator, final String indexPath, + final IndexCreator idxCreator, final Path indexPath, final SAMSequenceDictionary refDict) { super(encoder, asLocationAwareStream(outputStream)); this.indexer = idxCreator; @@ -98,21 +99,7 @@ public void close() throws IOException { indexer.setIndexSequenceDictionary(refDict); } final Index index = indexer.finalizeIndex(location.getPosition()); - // TODO: uncomment next line after https://github.com/samtools/htsjdk/pull/810 - // index.write(indexPath); - writeIndex(index); + index.write(indexPath); super.close(); } - - // TODO: remove comment and usage after https://github.com/samtools/htsjdk/pull/810 - private final void writeIndex(final Index index) throws IOException { - OutputStream outputStream = Files.newOutputStream(IOUtil.getPath(indexPath)); - if (index instanceof TabixIndex) { - outputStream = new BlockCompressedOutputStream(outputStream, null); - } else { - outputStream = new BufferedOutputStream(outputStream); - } - index.write(new LittleEndianOutputStream(outputStream)); - outputStream.close(); - } }