private Map<Integer, ByteArrayInputStream> getExternalBlockInputMap() { return external.entrySet() .stream() .collect(Collectors.toMap( Map.Entry::getKey, e -> new ByteArrayInputStream(e.getValue().getUncompressedContent()))); }
@Override public String toString() { final byte[] uncompressed = getUncompressedContent(); final byte[] compressed = getCompressedContent(); final String raw = Arrays.toString(Arrays.copyOf(uncompressed, Math.min(5, uncompressed.length))); final String comp = Arrays.toString(Arrays.copyOf(compressed, Math.min(5, compressed.length))); return String.format("compression method=%s, content type=%s, id=%d, raw size=%d, compressed size=%d, raw=%s, comp=%s.", getCompressionMethod().name(), getContentType().name(), getContentId(), getUncompressedContentSize(), getCompressedContentSize(), raw, comp); } }
@Override public String toString() { final byte[] uncompressed = getUncompressedContent(); final byte[] compressed = getCompressedContent(); final String raw = Arrays.toString(Arrays.copyOf(uncompressed, Math.min(5, uncompressed.length))); final String comp = Arrays.toString(Arrays.copyOf(compressed, Math.min(5, compressed.length))); return String.format("compression method=%s, content type=%s, id=%d, raw size=%d, compressed size=%d, raw=%s, comp=%s.", getCompressionMethod().name(), getContentType().name(), getContentId(), getUncompressedContentSize(), getCompressedContentSize(), raw, comp); } }
private Map<Integer, ByteArrayInputStream> getExternalBlockInputMap() { return external.entrySet() .stream() .collect(Collectors.toMap( Map.Entry::getKey, e -> new ByteArrayInputStream(e.getValue().getUncompressedContent()))); }
private void contentCheck(final Block actual, final byte[] expectedRaw, final byte[] expectedCompressed) { // raw and compressed data are equal to what was given Assert.assertEquals(actual.getUncompressedContent(), expectedRaw); Assert.assertEquals(actual.getUncompressedContentSize(), expectedRaw.length); Assert.assertEquals(actual.getCompressedContent(), expectedCompressed); Assert.assertEquals(actual.getCompressedContentSize(), expectedCompressed.length); }
private BitInputStream getCoreBlockInputStream() { return new DefaultBitInputStream(new ByteArrayInputStream(coreBlock.getUncompressedContent())); }
private BitInputStream getCoreBlockInputStream() { return new DefaultBitInputStream(new ByteArrayInputStream(coreBlock.getUncompressedContent())); }
inputStream = new ByteArrayInputStream(block.getUncompressedContent());
inputStream = new ByteArrayInputStream(block.getUncompressedContent());
/** * Read a COMPRESSION_HEADER Block from an InputStream and return its contents as a CompressionHeader * We do this instead of reading the InputStream directly because the Block content may be compressed * * @param cramVersion the CRAM version * @param blockStream the stream to read from * @return a new CompressionHeader from the input */ public static CompressionHeader read(final int cramVersion, final InputStream blockStream) { final Block block = Block.read(cramVersion, blockStream); if (block.getContentType() != BlockContentType.COMPRESSION_HEADER) throw new RuntimeIOException("Compression Header Block expected, found: " + block.getContentType().name()); try (final ByteArrayInputStream internalStream = new ByteArrayInputStream(block.getUncompressedContent())) { final CompressionHeader header = new CompressionHeader(); header.internalRead(internalStream); return header; } catch (final IOException e) { throw new RuntimeIOException(e); } }
/** * Read a COMPRESSION_HEADER Block from an InputStream and return its contents as a CompressionHeader * We do this instead of reading the InputStream directly because the Block content may be compressed * * @param cramVersion the CRAM version * @param blockStream the stream to read from * @return a new CompressionHeader from the input */ public static CompressionHeader read(final int cramVersion, final InputStream blockStream) { final Block block = Block.read(cramVersion, blockStream); if (block.getContentType() != BlockContentType.COMPRESSION_HEADER) throw new RuntimeIOException("Compression Header Block expected, found: " + block.getContentType().name()); try (final ByteArrayInputStream internalStream = new ByteArrayInputStream(block.getUncompressedContent())) { final CompressionHeader header = new CompressionHeader(); header.internalRead(internalStream); return header; } catch (final IOException e) { throw new RuntimeIOException(e); } }
private static void readSliceHeader(final int major, final Slice slice, final InputStream readInputStream) throws IOException { slice.headerBlock = Block.read(major, readInputStream); if (slice.headerBlock.getContentType() != BlockContentType.MAPPED_SLICE) throw new RuntimeException("Slice Header Block expected, found: " + slice.headerBlock.getContentType().name()); final InputStream parseInputStream = new ByteArrayInputStream(slice.headerBlock.getUncompressedContent()); slice.sequenceId = ITF8.readUnsignedITF8(parseInputStream); slice.alignmentStart = ITF8.readUnsignedITF8(parseInputStream); slice.alignmentSpan = ITF8.readUnsignedITF8(parseInputStream); slice.nofRecords = ITF8.readUnsignedITF8(parseInputStream); slice.globalRecordCounter = LTF8.readUnsignedLTF8(parseInputStream); slice.nofBlocks = ITF8.readUnsignedITF8(parseInputStream); slice.contentIDs = CramIntArray.array(parseInputStream); slice.embeddedRefBlockContentID = ITF8.readUnsignedITF8(parseInputStream); slice.refMD5 = new byte[16]; InputStreamUtils.readFully(parseInputStream, slice.refMD5, 0, slice.refMD5.length); final byte[] bytes = InputStreamUtils.readFully(parseInputStream); if (major >= CramVersions.CRAM_v3.major) { slice.sliceTags = BinaryTagCodec.readTags(bytes, 0, bytes.length, ValidationStringency.DEFAULT_STRINGENCY); SAMBinaryTagAndValue tags = slice.sliceTags; while (tags != null) { log.debug(String.format("Found slice tag: %s", SAMTag.makeStringTag(tags.tag))); tags = tags.getNext(); } } }
private static void readSliceHeader(final int major, final Slice slice, final InputStream readInputStream) { slice.headerBlock = Block.read(major, readInputStream); if (slice.headerBlock.getContentType() != BlockContentType.MAPPED_SLICE) throw new RuntimeException("Slice Header Block expected, found: " + slice.headerBlock.getContentType().name()); final InputStream parseInputStream = new ByteArrayInputStream(slice.headerBlock.getUncompressedContent()); slice.sequenceId = ITF8.readUnsignedITF8(parseInputStream); slice.alignmentStart = ITF8.readUnsignedITF8(parseInputStream); slice.alignmentSpan = ITF8.readUnsignedITF8(parseInputStream); slice.nofRecords = ITF8.readUnsignedITF8(parseInputStream); slice.globalRecordCounter = LTF8.readUnsignedLTF8(parseInputStream); slice.nofBlocks = ITF8.readUnsignedITF8(parseInputStream); slice.contentIDs = CramIntArray.array(parseInputStream); slice.embeddedRefBlockContentID = ITF8.readUnsignedITF8(parseInputStream); slice.refMD5 = new byte[16]; InputStreamUtils.readFully(parseInputStream, slice.refMD5, 0, slice.refMD5.length); final byte[] bytes = InputStreamUtils.readFully(parseInputStream); if (major >= CramVersions.CRAM_v3.major) { slice.sliceTags = BinaryTagCodec.readTags(bytes, 0, bytes.length, ValidationStringency.DEFAULT_STRINGENCY); SAMBinaryTagAndValue tags = slice.sliceTags; while (tags != null) { log.debug(String.format("Found slice tag: %s", SAMTag.makeStringTag(tags.tag))); tags = tags.getNext(); } } }