Source:
public void testIndexingOnTheFlyForPath() throws IOException { final VariantContextWriterBuilder builder = new VariantContextWriterBuilder() .setReferenceDictionary(dictionary) .setOption(Options.INDEX_ON_THE_FLY); try (FileSystem fs = Jimfs.newFileSystem("test", Configuration.unix())) { Path vcfPath = fs.getPath("testIndexingOnTheFlyForPath" + IOUtil.VCF_FILE_EXTENSION); Path vcfIdxPath = Tribble.indexPath(vcfPath); VariantContextWriter writer = builder.setOutputPath(vcfPath).build(); writer.close(); Assert.assertTrue(Files.exists(vcfIdxPath), String.format("VCF index not created for %s / %s", vcfPath, vcfIdxPath)); if (bcfIdx.exists()) bcfIdx.delete(); writer = builder.setOutputFile(bcf).build(); writer.close(); Assert.assertTrue(bcfIdx.exists(), String.format("BCF index not created for %s / %s", bcf, bcfIdx)); for (int i = 0; i < blockCompressedVCFs.size(); i++) { final File blockCompressed = blockCompressedVCFs.get(i); final File index = blockCompressedIndices.get(i); if (index.exists()) index.delete(); writer = builder.setOutputFile(blockCompressed).setReferenceDictionary(dictionary).build(); writer.close(); Assert.assertTrue(index.exists(), String .format("Block-compressed index not created for %s / %s", blockCompressed, index)); index.delete(); writer = builder.setReferenceDictionary(null).build(); writer.close(); Assert.assertTrue(index.exists(), String .format("Block-compressed index not created for %s / %s", blockCompressed, index)); } } }

Target:
public void testIndexingOnTheFlyForPath() throws IOException { final VariantContextWriterBuilder builder = new VariantContextWriterBuilder() .setReferenceDictionary(dictionary) .setOption(Options.INDEX_ON_THE_FLY); try (FileSystem fs = Jimfs.newFileSystem("test", Configuration.unix())) { final Path vcfPath = fs.getPath(vcf.getName()); final Path vcfIdxPath = Tribble.indexPath(vcfPath); try(final VariantContextWriter writer = builder.setOutputPath(vcfPath).build()) { } Assert.assertTrue(Files.exists(vcfIdxPath), String.format("VCF index not created for %s / %s", vcfPath, vcfIdxPath)); final Path bcfPath = fs.getPath(bcf.getName()); final Path bcfIdxPath = Tribble.indexPath(bcfPath); try(final VariantContextWriter writer = builder.setOutputPath(bcfPath).build()){ } Assert.assertTrue(Files.exists(bcfIdxPath), String.format("BCF index not created for %s / %s", bcfPath, bcfIdxPath)); for (int i = 0; i < blockCompressedVCFs.size(); i++) { final File blockCompressed = blockCompressedVCFs.get(i); final File index = blockCompressedIndices.get(i); final Path blockCompressedPath = fs.getPath(blockCompressed.getName()); final Path indexPath = fs.getPath(index.getName()); Assert.assertFalse(Files.exists(indexPath)); try(VariantContextWriter writer = builder.setOutputPath(blockCompressedPath).setReferenceDictionary(dictionary).build()){ } Assert.assertTrue(Files.exists(indexPath), String .format("Block-compressed index not created for %s / %s", blockCompressedPath, indexPath)); Files.delete(indexPath); try (VariantContextWriter writer = builder.setReferenceDictionary(null).build()){ } Assert.assertTrue(Files.exists(indexPath), String .format("Block-compressed index not created for %s / %s", blockCompressedPath, indexPath)); } } }