# 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 final int`
`MAX_BYTES`

## Constructor Summary

Constructors
Constructor
Description
`ITF8()`

## Method Summary

Modifier and Type
Method
Description
`static int`
`readUnsignedITF8(byte[] data)`
Reads an unsigned (32 bit) integer from an array of bytes.
`static int`
`readUnsignedITF8(CRAMByteReader reader)`
Reads an unsigned ITF8 integer from a `CRAMByteReader`.
`static int`
`readUnsignedITF8(InputStream inputStream)`
Reads an unsigned (32 bit) integer from an `InputStream`.
`static int`
`readUnsignedITF8(ByteBuffer buffer)`
Reads an unsigned (32 bit) integer from a `ByteBuffer`.
`static byte[]`
`writeUnsignedITF8(int value)`
Writes an unsigned (32 bit) integer to a byte new array encoded as ITF8.
`static int`
`writeUnsignedITF8(int value, CRAMByteWriter writer)`
Writes an unsigned ITF8 integer to a `CRAMByteWriter`.
`static int`
`writeUnsignedITF8(int value, OutputStream outputStream)`
Writes an unsigned (32 bit) integer to an `OutputStream` encoded as ITF8.
`static int`
`writeUnsignedITF8(int value, ByteBuffer buffer)`
Writes an unsigned (32 bit) integer to an `OutputStream` encoded as ITF8.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### MAX_BYTES

public static final int MAX_BYTES

See Also:
  - Constant Field Values

## Constructor Details

### ITF8

public ITF8()

## Method Details

### readUnsignedITF8

public static int readUnsignedITF8(InputStream inputStream)
Reads an unsigned (32 bit) integer from an `InputStream`. 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 a `ByteBuffer`. 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 an `OutputStream` encoded as ITF8. The sign bit is interpreted as a value bit.

Parameters:
  `value` - the value to be written out
  `outputStream` - 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 an `OutputStream` encoded as ITF8. The sign bit is interpreted as a value bit.

Parameters:
  `value` - the value to be written out
  `buffer` - the `ByteBuffer` to write to

### readUnsignedITF8

public static int readUnsignedITF8(CRAMByteReader reader)
Reads an unsigned ITF8 integer from a `CRAMByteReader`. Equivalent to the InputStream version but avoids synchronized method call overhead.

Parameters:
  `reader` - the reader to read from
Returns:
  the decoded value

### writeUnsignedITF8

public static int writeUnsignedITF8(int value, CRAMByteWriter writer)
Writes an unsigned ITF8 integer to a `CRAMByteWriter`. Equivalent to the OutputStream version but avoids synchronized method call overhead.

Parameters:
  `value` - the value to write
  `writer` - the writer to write to
Returns:
  number of bits written

### 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