/** * Protected constructor of a generic Block, to be called by static factory methods and subclasses. * * @param compressionMethod the block compression method. Can be RAW, if uncompressed * @param contentType whether this is a header or data block, and which kind * @param compressedContent the compressed form of the data to be stored in this block * @param uncompressedLength the length of the content stored in this block when uncompressed */ protected Block(final BlockCompressionMethod compressionMethod, final BlockContentType contentType, final byte[] compressedContent, final int uncompressedLength) { this.compressionMethod = compressionMethod; this.contentType = contentType; this.compressedContent = compressedContent; this.uncompressedLength = uncompressedLength; // causes test failures. https://github.com/samtools/htsjdk/issues/1232 // if (type == BlockContentType.EXTERNAL && getContentId() == Block.NO_CONTENT_ID) { // throw new CRAMException("Valid Content ID required for external blocks."); // } if (contentType != BlockContentType.EXTERNAL && getContentId() != Block.NO_CONTENT_ID) { throw new CRAMException("Cannot set a Content ID for non-external blocks."); } }
/** * Protected constructor of a generic Block, to be called by static factory methods and subclasses. * * @param compressionMethod the block compression method. Can be RAW, if uncompressed * @param contentType whether this is a header or data block, and which kind * @param compressedContent the compressed form of the data to be stored in this block * @param uncompressedLength the length of the content stored in this block when uncompressed */ protected Block(final BlockCompressionMethod compressionMethod, final BlockContentType contentType, final byte[] compressedContent, final int uncompressedLength) { this.compressionMethod = compressionMethod; this.contentType = contentType; this.compressedContent = compressedContent; this.uncompressedLength = uncompressedLength; // causes test failures. https://github.com/samtools/htsjdk/issues/1232 // if (type == BlockContentType.EXTERNAL && getContentId() == Block.NO_CONTENT_ID) { // throw new CRAMException("Valid Content ID required for external blocks."); // } if (contentType != BlockContentType.EXTERNAL && getContentId() != Block.NO_CONTENT_ID) { throw new CRAMException("Cannot set a Content ID for non-external blocks."); } }
private static void readSliceBlocks(final int major, final Slice slice, final InputStream inputStream) { slice.external = new HashMap<>(); for (int i = 0; i < slice.nofBlocks; i++) { final Block block = Block.read(major, inputStream); switch (block.getContentType()) { case CORE: slice.coreBlock = block; break; case EXTERNAL: if (slice.embeddedRefBlockContentID == block.getContentId()) { slice.embeddedRefBlock = block; } slice.external.put(block.getContentId(), block); break; default: throw new RuntimeException("Not a slice block, content type id " + block.getContentType().name()); } } }
private static void readSliceBlocks(final int major, final Slice slice, final InputStream inputStream) throws IOException { slice.external = new HashMap<>(); for (int i = 0; i < slice.nofBlocks; i++) { final Block block = Block.read(major, inputStream); switch (block.getContentType()) { case CORE: slice.coreBlock = block; break; case EXTERNAL: if (slice.embeddedRefBlockContentID == block.getContentId()) { slice.embeddedRefBlock = block; } slice.external.put(block.getContentId(), block); break; default: throw new RuntimeException("Not a slice block, content type id " + block.getContentType().name()); } } }
@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 void doWrite(final OutputStream outputStream) throws IOException { outputStream.write(getCompressionMethod().getMethodId()); outputStream.write(getContentType().getContentTypeId()); ITF8.writeUnsignedITF8(getContentId(), outputStream); ITF8.writeUnsignedITF8(getCompressedContentSize(), outputStream); ITF8.writeUnsignedITF8(getUncompressedContentSize(), outputStream); outputStream.write(getCompressedContent()); }
private void doWrite(final OutputStream outputStream) throws IOException { outputStream.write(getCompressionMethod().getMethodId()); outputStream.write(getContentType().getContentTypeId()); ITF8.writeUnsignedITF8(getContentId(), outputStream); ITF8.writeUnsignedITF8(getCompressedContentSize(), outputStream); ITF8.writeUnsignedITF8(getUncompressedContentSize(), outputStream); outputStream.write(getCompressedContent()); }