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 Details

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