Class CRAMByteReader
java.lang.Object
htsjdk.samtools.cram.io.CRAMByteReader
Unsynchronized reader over a
byte[] for CRAM codec decode operations. Replaces
ByteArrayInputStream in the hot decode path to eliminate the overhead of
synchronized read() methods (which showed up as ~10% of total decode CPU in profiling).
This is a final class (not an InputStream subclass) so the JIT can inline its methods. Thread safety is explicitly not provided — CRAM codec operations are single-threaded.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCRAMByteReader(byte[] buf) Create a reader over the given byte array, starting at position 0. -
Method Summary
Modifier and TypeMethodDescriptionintReturn the number of bytes remaining to be read.byte[]Return a reference to the underlying byte array.intReturn the current read position within the buffer.intread()Read one byte, returning it as an unsigned int (0-255), or -1 if at end of buffer.intread(byte[] b, int off, int len) Read up tolenbytes into the destination array.byte[]readFully(int len) Read exactlylenbytes, returning them as a new array.
-
Constructor Details
-
CRAMByteReader
public CRAMByteReader(byte[] buf) Create a reader over the given byte array, starting at position 0.- Parameters:
buf- the data to read from (not copied — caller must not modify while reading)
-
-
Method Details
-
read
public int read()Read one byte, returning it as an unsigned int (0-255), or -1 if at end of buffer. Matches the contract ofInputStream.read().- Returns:
- the next byte as an unsigned int, or -1 at end of data
-
read
public int read(byte[] b, int off, int len) Read up tolenbytes into the destination array.- Parameters:
b- destination arrayoff- offset in destination to start writinglen- maximum number of bytes to read- Returns:
- the number of bytes actually read, or -1 if at end of data
-
readFully
public byte[] readFully(int len) Read exactlylenbytes, returning them as a new array.- Parameters:
len- number of bytes to read- Returns:
- a new byte array of length
len - Throws:
IllegalStateException- if fewer thanlenbytes remain
-
available
public int available()Return the number of bytes remaining to be read. -
getPosition
public int getPosition()Return the current read position within the buffer. -
getBuffer
public byte[] getBuffer()Return a reference to the underlying byte array.
-