private static void writeTerminatorBlock(final OutputStream out, final SAMFormat samOutputFormat) throws IOException { if (SAMFormat.CRAM == samOutputFormat) { CramIO.issueEOF(CramVersions.DEFAULT_CRAM_VERSION, out); // terminate with CRAM EOF container } else if (SAMFormat.BAM == samOutputFormat) { out.write(BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK); // add the BGZF terminator } // no terminator for SAM }
private static void writeTerminatorBlock(final OutputStream out, final SAMFormat samOutputFormat) throws IOException { if (SAMFormat.CRAM == samOutputFormat) { CramIO.issueEOF(CramVersions.DEFAULT_CRAM_VERSION, out); // terminate with CRAM EOF container } else if (SAMFormat.BAM == samOutputFormat) { out.write(BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK); // add the BGZF terminator } // no terminator for SAM }
private static void writeTerminatorBlock(final OutputStream out, final SAMFormat samOutputFormat) throws IOException { if (SAMFormat.CRAM == samOutputFormat) { CramIO.issueEOF(CramVersions.DEFAULT_CRAM_VERSION, out); // terminate with CRAM EOF container } else { out.write(BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK); // add the BGZF terminator } }
/** * Finish writing to the stream. Flushes the record cache and optionally emits an EOF container. * @param writeEOFContainer true if an EOF container should be written. Only use false if writing a CRAM file * fragment which will later be aggregated into a complete CRAM file. */ public void finish(final boolean writeEOFContainer) { try { if (!samRecords.isEmpty()) { flushContainer(); } if (writeEOFContainer) { CramIO.issueEOF(cramVersion, outputStream); } outputStream.flush(); if (indexer != null) { indexer.finish(); } outputStream.close(); } catch (final IOException e) { throw new RuntimeIOException(e); } catch (final IllegalAccessException e) { throw new RuntimeException(e); } }
CramIO.issueEOF(cramVersion, outputStream);
/** * Finish writing to the stream. Flushes the record cache and optionally emits an EOF container. * @param writeEOFContainer true if an EOF container should be written. Only use false if writing a CRAM file * fragment which will later be aggregated into a complete CRAM file. */ public void finish(final boolean writeEOFContainer) { try { if (!samRecords.isEmpty()) { flushContainer(); } if (writeEOFContainer) { CramIO.issueEOF(cramVersion, outputStream); } outputStream.flush(); if (indexer != null) { indexer.finish(); } outputStream.close(); } catch (final IOException e) { throw new RuntimeIOException(e); } catch (final IllegalAccessException e) { throw new RuntimeException(e); } }
/** * Finish writing to the stream. Flushes the record cache and optionally * emits an EOF container. * * @param writeEOFContainer * true if an EOF container should be written. Only use false if * writing a CRAM file fragment which will later be aggregated * into a complete CRAM file. */ public void finish(final boolean writeEOFContainer) { try { if (!samRecords.isEmpty()) { flushContainer(); } if (writeEOFContainer) { CramIO.issueEOF(cramVersion, outputStream); } outputStream.flush(); if (indexer != null) { indexer.finish(); } outputStream.close(); } catch (final IOException e) { throw new RuntimeIOException(e); } catch (final IllegalAccessException e) { throw new RuntimeException(e); } }
@Test(dataProvider = "eof") public void testEOF(final Version version) throws IOException { final ContainerParser parser = new ContainerParser(ContainerFactoryTest.getSAMFileHeaderForTests()); try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { CramIO.issueEOF(version, baos); final Container container = ContainerIO.readContainer(version, new ByteArrayInputStream(baos.toByteArray())); Assert.assertTrue(container.isEOF()); Assert.assertTrue(parser.getRecords(container, null, ValidationStringency.STRICT).isEmpty()); } }
@Test public void testCheckHeaderAndEOF_v2() throws IOException { final String id = "testid"; final CramHeader cramHeader = new CramHeader(CramVersions.CRAM_v2_1, id, new SAMFileHeader()); final File file = File.createTempFile("test", ".cram"); file.deleteOnExit(); final FileOutputStream fos = new FileOutputStream(file); CramIO.writeCramHeader(cramHeader, fos); CramIO.issueEOF(cramHeader.getVersion(), fos); fos.close(); Assert.assertTrue(CramIO.checkHeaderAndEOF(file)); file.delete(); }
@Test public void testCheckHeaderAndEOF_v3() throws IOException { final String id = "testid"; final CramHeader cramHeader = new CramHeader(CramVersions.CRAM_v3, id, new SAMFileHeader()); final File file = File.createTempFile("test", ".cram"); file.deleteOnExit(); final FileOutputStream fos = new FileOutputStream(file); CramIO.writeCramHeader(cramHeader, fos); CramIO.issueEOF(cramHeader.getVersion(), fos); fos.close(); Assert.assertTrue(CramIO.checkHeaderAndEOF(file)); file.delete(); }
CramIO.issueEOF(cramHeader.getVersion(), cramOutputStream); cramOutputStream.close();
final FileOutputStream fos = new FileOutputStream(file); CramIO.writeCramHeader(cramHeader, fos); CramIO.issueEOF(cramHeader.getVersion(), fos); fos.close(); final long length = file.length();