Class Block
- java.lang.Object
-
- htsjdk.samtools.cram.structure.block.Block
-
- Direct Known Subclasses:
ExternalBlock
public class Block extends Object
Class representing CRAM block concept and some methods to operate with block content. CRAM block is used to hold some (usually homogeneous) binary data. An external compression can be applied to the content of a block. The class provides some instantiation static methods, for example to read a block from an input stream. Blocks can be written out to an output stream, this may be considered as a way to serialize/deserialize blocks.
-
-
Field Summary
Fields Modifier and Type Field Description static int
NO_CONTENT_ID
Only external blocks have meaningful Content IDs Other blocks are required to have a Content ID of 0
-
Constructor Summary
Constructors Modifier Constructor Description protected
Block(BlockCompressionMethod compressionMethod, BlockContentType contentType, byte[] compressedContent, int uncompressedLength)
Protected constructor of a generic Block, to be called by static factory methods and subclasses.protected
Block(BlockContentType contentType, byte[] rawContent)
Protected constructor of a generic Block, to be called by static factory methods and subclasses.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Block
createRawCompressionHeaderBlock(byte[] rawContent)
Create a new compression header block with the given uncompressed content.static Block
createRawCoreDataBlock(byte[] rawContent)
Create a new core data block with the given uncompressed content.static Block
createRawFileHeaderBlock(byte[] rawContent)
Create a new file header block with the given uncompressed content.static Block
createRawSliceHeaderBlock(byte[] rawContent)
Create a new slice header block with the given uncompressed content.byte[]
getCompressedContent()
int
getCompressedContentSize()
BlockCompressionMethod
getCompressionMethod()
int
getContentId()
Return the External Content ID for this block.BlockContentType
getContentType()
Identifies whether this is a header or data block, and which kindbyte[]
getUncompressedContent()
Uncompress the stored block content (if not RAW) and return the uncompressed content.int
getUncompressedContentSize()
static Block
read(int major, InputStream inputStream)
Deserialize the Block from theInputStream
.String
toString()
void
write(int major, OutputStream outputStream)
Write the block out to the the specifiedOutputStream
.
-
-
-
Field Detail
-
NO_CONTENT_ID
public static final int NO_CONTENT_ID
Only external blocks have meaningful Content IDs Other blocks are required to have a Content ID of 0- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Block
protected Block(BlockCompressionMethod compressionMethod, BlockContentType contentType, byte[] compressedContent, int uncompressedLength)
Protected constructor of a generic Block, to be called by static factory methods and subclasses.- Parameters:
compressionMethod
- the block compression method. Can be RAW, if uncompressedcontentType
- whether this is a header or data block, and which kindcompressedContent
- the compressed form of the data to be stored in this blockuncompressedLength
- the length of the content stored in this block when uncompressed
-
Block
protected Block(BlockContentType contentType, byte[] rawContent)
Protected constructor of a generic Block, to be called by static factory methods and subclasses. Creates RAW blocks only.- Parameters:
contentType
- whether this is a header or data block, and which kindrawContent
- the raw data to be stored in this block
-
-
Method Detail
-
createRawFileHeaderBlock
public static Block createRawFileHeaderBlock(byte[] rawContent)
Create a new file header block with the given uncompressed content. The block will have RAW (no) compression and FILE_HEADER content type.- Parameters:
rawContent
- the uncompressed content of the block- Returns:
- a new
Block
object
-
createRawCompressionHeaderBlock
public static Block createRawCompressionHeaderBlock(byte[] rawContent)
Create a new compression header block with the given uncompressed content. The block will have RAW (no) compression and COMPRESSION_HEADER content type.- Parameters:
rawContent
- the uncompressed content of the block- Returns:
- a new
Block
object
-
createRawSliceHeaderBlock
public static Block createRawSliceHeaderBlock(byte[] rawContent)
Create a new slice header block with the given uncompressed content. The block will have RAW (no) compression and MAPPED_SLICE content type.- Parameters:
rawContent
- the uncompressed content of the block- Returns:
- a new
Block
object
-
createRawCoreDataBlock
public static Block createRawCoreDataBlock(byte[] rawContent)
Create a new core data block with the given uncompressed content. The block will have RAW (no) compression and CORE content type.- Parameters:
rawContent
- the uncompressed content of the block- Returns:
- a new
Block
object
-
getCompressionMethod
public final BlockCompressionMethod getCompressionMethod()
-
getContentType
public final BlockContentType getContentType()
Identifies whether this is a header or data block, and which kind- Returns:
- the CRAM content type of the block
-
getContentId
public int getContentId()
Return the External Content ID for this block. Only ExternalBlocks have a meaningful Content ID, so that class overrides this method.- Returns:
- the External Content ID, or NO_CONTENT_ID
-
getUncompressedContent
public final byte[] getUncompressedContent()
Uncompress the stored block content (if not RAW) and return the uncompressed content.- Returns:
- The uncompressed block content.
- Throws:
CRAMException
- The uncompressed length did not match what was expected.
-
getUncompressedContentSize
public int getUncompressedContentSize()
- Returns:
- The size of the uncompressed content in bytes.
-
getCompressedContent
public final byte[] getCompressedContent()
- Returns:
- The compressed block content.
-
getCompressedContentSize
public final int getCompressedContentSize()
- Returns:
- The size of the compressed content in bytes.
-
read
public static Block read(int major, InputStream inputStream)
Deserialize the Block from theInputStream
. The reading is parameterized by the major CRAM version number.- Parameters:
major
- CRAM version major numberinputStream
- input stream to read the block from- Returns:
- a subtype of
Block
object with fields and content from the input stream
-
write
public final void write(int major, OutputStream outputStream)
Write the block out to the the specifiedOutputStream
. The method is parameterized with the CRAM major version number.- Parameters:
major
- CRAM version major numberoutputStream
- output stream to write to
-
-