Package htsjdk.samtools.cram.io
Class ITF8
- java.lang.Object
-
- htsjdk.samtools.cram.io.ITF8
-
public class ITF8 extends Object
Methods to read and write int values as per ITF8 specification in CRAM. ITF8 encodes ints as 1 to 5 bytes depending on the highest set bit. (using 1-based counting) If highest bit < 8: write out [bits 1-8] Highest bit = 8-14: write a byte 1,0,[bits 9-14] write out [bits 1-8] Highest bit = 15-21: write a byte 1,1,0,[bits 17-21] write out [bits 9-16] write out [bits 1-8] Highest bit = 22-28: write a byte 1,1,1,0,[bits 25-28] write out [bits 17-24] write out [bits 9-16] write out [bits 1-8] Highest bit > 28: write a byte 1,1,1,1,[bits 29-32] write out [bits 21-28] **** note the change in pattern here write out [bits 13-20] write out [bits 5-12] write out [bits 1-8]
-
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_BYTES
-
Constructor Summary
Constructors Constructor Description ITF8()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
readUnsignedITF8(byte[] data)
Reads an unsigned (32 bit) integer from an array of bytes.static int
readUnsignedITF8(InputStream inputStream)
Reads an unsigned (32 bit) integer from anInputStream
.static int
readUnsignedITF8(ByteBuffer buffer)
Reads an unsigned (32 bit) integer from aByteBuffer
.static byte[]
writeUnsignedITF8(int value)
Writes an unsigned (32 bit) integer to a byte new array encoded as ITF8.static int
writeUnsignedITF8(int value, OutputStream outputStream)
Writes an unsigned (32 bit) integer to anOutputStream
encoded as ITF8.static int
writeUnsignedITF8(int value, ByteBuffer buffer)
Writes an unsigned (32 bit) integer to anOutputStream
encoded as ITF8.
-
-
-
Field Detail
-
MAX_BYTES
public static final int MAX_BYTES
- See Also:
- Constant Field Values
-
-
Method Detail
-
readUnsignedITF8
public static int readUnsignedITF8(InputStream inputStream)
Reads an unsigned (32 bit) integer from anInputStream
. The sign bit should be interpreted as a value bit.- Parameters:
inputStream
- the stream to read from- Returns:
- the value read
-
readUnsignedITF8
public static int readUnsignedITF8(ByteBuffer buffer)
Reads an unsigned (32 bit) integer from aByteBuffer
. The sign bit should be interpreted as a value bit.- Parameters:
buffer
- the bytes to read from- Returns:
- unsigned integer value from the buffer
-
readUnsignedITF8
public static int readUnsignedITF8(byte[] data)
Reads an unsigned (32 bit) integer from an array of bytes. The sign bit should be interpreted as a value bit.- Parameters:
data
- the bytes to read from- Returns:
- the value read
-
writeUnsignedITF8
public static int writeUnsignedITF8(int value, OutputStream outputStream)
Writes an unsigned (32 bit) integer to anOutputStream
encoded as ITF8. The sign bit is interpreted as a value bit.- Parameters:
value
- the value to be written outoutputStream
- the stream to write to- Returns:
- number of bits written
-
writeUnsignedITF8
public static int writeUnsignedITF8(int value, ByteBuffer buffer)
Writes an unsigned (32 bit) integer to anOutputStream
encoded as ITF8. The sign bit is interpreted as a value bit.- Parameters:
value
- the value to be written outbuffer
- theByteBuffer
to write to
-
writeUnsignedITF8
public static byte[] writeUnsignedITF8(int value)
Writes an unsigned (32 bit) integer to a byte new array encoded as ITF8. The sign bit is interpreted as a value bit.- Parameters:
value
- the value to be written out- Returns:
- the bytes holding ITF8 representation of the value
-
-