Class HuffmanCodec

java.lang.Object
io.helidon.common.buffers.HuffmanCodec

public final class HuffmanCodec extends Object
HPACK and QPACK Huffman codec defined by RFC 7541, Appendix B.
  • Method Details

    • encodedLength

      public static int encodedLength(CharSequence value)
      Calculate the encoded length of a value.
      Parameters:
      value - octet-valued characters to encode
      Returns:
      encoded byte count
      Throws:
      IllegalArgumentException - if a character is outside the octet range or the encoded length exceeds the supported array range
    • encode

      public static int encode(CharSequence value, byte[] destination)
      Encode a value into a destination byte array.

      If encoding is unsuccessful, the destination contents are undefined and must be discarded. A destination that is too small can be detected before all characters have been validated.

      Parameters:
      value - octet-valued characters to encode
      destination - destination byte array
      Returns:
      encoded byte count, or -1 if the destination is too small
      Throws:
      IllegalArgumentException - if a character is outside the octet range
    • decode

      public static int decode(BufferData source, int encodedLength, byte[] destination)
      Decode bytes into a destination byte array.

      Invalid input may partially advance the source and modify the destination. Range and capacity failures are detected before either is modified.

      Parameters:
      source - encoded bytes
      encodedLength - encoded byte count
      destination - decoded byte destination
      Returns:
      decoded byte count
      Throws:
      IndexOutOfBoundsException - if the encoded range exceeds the source or the destination cannot hold the maximum possible decoded value
      IllegalArgumentException - if the input is malformed
    • decode

      public static void decode(BufferData source, int encodedLength, Appendable destination)
      Decode bytes into an appendable.

      Invalid input or an append failure may partially advance the source and modify the destination. Range failures are detected before either is modified.

      Parameters:
      source - encoded bytes
      encodedLength - encoded byte count
      destination - decoded character destination
      Throws:
      IndexOutOfBoundsException - if the encoded range exceeds the source
      IllegalArgumentException - if the input is malformed
      UncheckedIOException - if appending fails