# Class HPackHuffman

java.lang.Object
org.apache.coyote.http2.HPackHuffman

public class HPackHuffman extends Object
Utility class for Huffman encoding and decoding used in HPACK compression for HTTP/2 headers.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`protected static class`
`HPackHuffman.HuffmanCode`
Represents a Huffman code with a value and bit length.

## Field Summary

Fields
Modifier and Type
Field
Description
`protected static final StringManager`
`sm`
String manager for error messages.

## Method Summary

Modifier and Type
Method
Description
`static void`
`decode(ByteBuffer data, int length, StringBuilder target)`
Deprecated.
Will be removed in Tomcat 12.
`static void`
`decode(ByteBuffer data, int length, StringBuilder target, boolean isFieldName)`
Decodes a huffman encoded string into the target StringBuilder.
`static boolean`
`encode(ByteBuffer buffer, String toEncode)`
Encodes the given string into the buffer.
`static boolean`
`encode(ByteBuffer buffer, String toEncode, boolean forceLowercase)`
Deprecated.
Unused.

### Methods inherited from class Object

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

## Field Details

### sm

protected static final StringManager sm
String manager for error messages.

## Method Details

### decode

@Deprecated public static void decode(ByteBuffer data, int length, StringBuilder target) throws org.apache.coyote.http2.HpackException
Deprecated.
Will be removed in Tomcat 12. Use `decode(ByteBuffer, int, StringBuilder, boolean)`
Decodes a huffman encoded string into the target StringBuilder. There must be enough space left in the buffer for this method to succeed.

Parameters:
  `data` - The byte buffer
  `length` - The length of data from the buffer to decode
  `target` - The target for the decompressed data
Throws:
  `org.apache.coyote.http2.HpackException` - If the Huffman encoded value in HPACK headers did not end with EOS padding

### decode

public static void decode(ByteBuffer data, int length, StringBuilder target, boolean isFieldName) throws org.apache.coyote.http2.HpackException
Decodes a huffman encoded string into the target StringBuilder. There must be enough space left in the buffer for this method to succeed.

Parameters:
  `data` - The byte buffer
  `length` - The length of data from the buffer to decode
  `target` - The target for the decompressed data
  `isFieldName` - `true` if a field name is being decoded (names have a more restrictive set of allowed characters than field values)
Throws:
  `org.apache.coyote.http2.HpackException` - If the Huffman encoded value in HPACK headers did not end with EOS padding

### encode

@Deprecated public static boolean encode(ByteBuffer buffer, String toEncode, boolean forceLowercase)
Deprecated.
Unused. This method will be removed in Tomcat 12 onwards.
Encodes the given string into the buffer. If there is not enough space in the buffer, or the encoded version is bigger than the original it will return false and not modify the buffers position.

Parameters:
  `buffer` - The buffer to encode into
  `toEncode` - The string to encode
  `forceLowercase` - If the string should be encoded in lower case
Returns:
  true if encoding succeeded

### encode

public static boolean encode(ByteBuffer buffer, String toEncode)
Encodes the given string into the buffer. If there is not enough space in the buffer, or the encoded version is bigger than the original it will return false and not modify the buffers position.

Parameters:
  `buffer` - The buffer to encode into
  `toEncode` - The string to encode
Returns:
  true if encoding succeeded