private static long writeContainerForSamFileHeader(final int major, final SAMFileHeader samFileHeader, final OutputStream os) { final byte[] data = toByteArray(samFileHeader); final int length = Math.max(1024, data.length + data.length / 2); final byte[] blockContent = new byte[length]; System.arraycopy(data, 0, blockContent, 0, Math.min(data.length, length)); final Block block = Block.createRawFileHeaderBlock(blockContent); final Container container = new Container(); container.blockCount = 1; container.blocks = new Block[]{block}; container.landmarks = new int[0]; container.slices = new Slice[0]; container.alignmentSpan = Slice.NO_ALIGNMENT_SPAN; container.alignmentStart = Slice.NO_ALIGNMENT_START; container.bases = 0; container.globalRecordCounter = 0; container.nofRecords = 0; container.sequenceId = 0; final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); block.write(major, byteArrayOutputStream); container.containerByteSize = byteArrayOutputStream.size(); final int containerHeaderByteSize = ContainerIO.writeContainerHeader(major, container, os); try { os.write(byteArrayOutputStream.toByteArray(), 0, byteArrayOutputStream.size()); } catch (final IOException e) { throw new RuntimeIOException(e); } return containerHeaderByteSize + byteArrayOutputStream.size(); }
countingInputStream.close(); final Block block = Block.createRawFileHeaderBlock(toByteArray(newHeader.getSamFileHeader())); final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); block.write(newHeader.getVersion().major, byteArrayOutputStream);
private static long writeContainerForSamFileHeader(final int major, final SAMFileHeader samFileHeader, final OutputStream os) throws IOException { final byte[] data = toByteArray(samFileHeader); final int length = Math.max(1024, data.length + data.length / 2); final byte[] blockContent = new byte[length]; System.arraycopy(data, 0, blockContent, 0, Math.min(data.length, length)); final Block block = Block.createRawFileHeaderBlock(blockContent); final Container container = new Container(); container.blockCount = 1; container.blocks = new Block[]{block}; container.landmarks = new int[0]; container.slices = new Slice[0]; container.alignmentSpan = Slice.NO_ALIGNMENT_SPAN; container.alignmentStart = Slice.NO_ALIGNMENT_START; container.bases = 0; container.globalRecordCounter = 0; container.nofRecords = 0; container.sequenceId = 0; final ExposedByteArrayOutputStream byteArrayOutputStream = new ExposedByteArrayOutputStream(); block.write(major, byteArrayOutputStream); container.containerByteSize = byteArrayOutputStream.size(); final int containerHeaderByteSize = ContainerIO.writeContainerHeader(major, container, os); os.write(byteArrayOutputStream.getBuffer(), 0, byteArrayOutputStream.size()); return containerHeaderByteSize + byteArrayOutputStream.size(); }
countingInputStream.close(); final Block block = Block.createRawFileHeaderBlock(toByteArray(newHeader.getSamFileHeader())); final ExposedByteArrayOutputStream byteArrayOutputStream = new ExposedByteArrayOutputStream(); block.write(newHeader.getVersion().major, byteArrayOutputStream);