Class HuffmanEncoder

java.lang.Object
org.eclipse.jetty.http.compression.HuffmanEncoder

public class HuffmanEncoder extends Object

Used to encode strings Huffman encoding.

Characters are encoded with ISO-8859-1, if any multi-byte characters or control characters are present the encoder will throw EncodingException.

  • Method Details

    • octetsNeeded

      public static int octetsNeeded(String s)
      Parameters:
      s - the string to encode.
      Returns:
      the number of octets needed to encode the string, or -1 if it cannot be encoded.
    • octetsNeeded

      public static int octetsNeeded(byte[] b)
      Parameters:
      b - the byte array to encode.
      Returns:
      the number of octets needed to encode the bytes, or -1 if it cannot be encoded.
    • encode

      public static void encode(ByteBuffer buffer, String s)
      Parameters:
      buffer - the buffer to encode into.
      s - the string to encode.
    • octetsNeededLowerCase

      public static int octetsNeededLowerCase(String s)
      Parameters:
      s - the string to encode in lowercase.
      Returns:
      the number of octets needed to encode the string, or -1 if it cannot be encoded.
    • encodeLowerCase

      public static void encodeLowerCase(ByteBuffer buffer, String s)
      Parameters:
      buffer - the buffer to encode into in lowercase.
      s - the string to encode.
    • encodeWithLength

      public static void encodeWithLength(ByteBuffer buffer, int prefix, String s)

      Encode s, preceded by the number of octets it encodes to, written as an n-bit integer with the given prefix.

      The length precedes the content but is not known until the content has been encoded, which would need a separate pass over s to compute. Instead the content is encoded first, into the space after the octet that holds the length, and the length is then filled in. That octet only has room for a length below the prefix maximum, which every string of fewer than (1 << prefix) - 1 encoded octets satisfies; for the rare longer string the buffer is rewound and both are written the direct way.

      Parameters:
      buffer - the buffer to encode into
      prefix - the prefix used to encode the length, in bits
      s - the string to encode
    • encodeLowerCaseWithLength

      public static void encodeLowerCaseWithLength(ByteBuffer buffer, int prefix, String s)
      As encodeWithLength(ByteBuffer, int, String), encoding s in lowercase.
      Parameters:
      buffer - the buffer to encode into
      prefix - the prefix used to encode the length, in bits
      s - the string to encode