Class Decoder
- java.lang.Object
-
- jdk.incubator.http.internal.hpack.Decoder
-
public final class Decoder extends java.lang.Object
Decodes headers from their binary representation.Typical lifecycle looks like this:
- Since:
- 9
-
-
Constructor Summary
Constructors Constructor Description Decoder(int capacity)
Constructs aDecoder
with the specified initial capacity of the header table.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
decode(java.nio.ByteBuffer headerBlock, boolean endOfHeaderBlock, DecodingCallback consumer)
Decodes a header block from the given buffer to the given callback.void
setMaxCapacity(int capacity)
Sets a maximum capacity of the header table.
-
-
-
Constructor Detail
-
Decoder
public Decoder(int capacity)
Constructs aDecoder
with the specified initial capacity of the header table.The value has to be agreed between decoder and encoder out-of-band, e.g. by a protocol that uses HPACK (see 4.2. Maximum Table Size).
- Parameters:
capacity
- a non-negative integer- Throws:
java.lang.IllegalArgumentException
- if capacity is negative
-
-
Method Detail
-
setMaxCapacity
public void setMaxCapacity(int capacity)
Sets a maximum capacity of the header table.The value has to be agreed between decoder and encoder out-of-band, e.g. by a protocol that uses HPACK (see 4.2. Maximum Table Size).
- Parameters:
capacity
- a non-negative integer- Throws:
java.lang.IllegalArgumentException
- if capacity is negative
-
decode
public void decode(java.nio.ByteBuffer headerBlock, boolean endOfHeaderBlock, DecodingCallback consumer)
Decodes a header block from the given buffer to the given callback.Suppose a header block is represented by a sequence of
ByteBuffer
s in the form ofIterator<ByteBuffer>
. And the consumer of decoded headers is represented by the callback. Then to decode the header block, the following approach might be used:while (buffers.hasNext()) { ByteBuffer input = buffers.next(); decoder.decode(input, callback, !buffers.hasNext()); }
The decoder reads as much as possible of the header block from the given buffer, starting at the buffer's position, and increments its position to reflect the bytes read. The buffer's mark and limit will not be modified.
Once the method is invoked with
endOfHeaderBlock == true
, the current header block is deemed ended, and inconsistencies, if any, are reported immediately by throwing anUncheckedIOException
.Each callback method is called only after the implementation has processed the corresponding bytes. If the bytes revealed a decoding error, the callback method is not called.
In addition to exceptions thrown directly by the method, any exceptions thrown from the
callback
will bubble up.- Parameters:
headerBlock
- the chunk of the header block, may be emptyendOfHeaderBlock
- true if the chunk is the final (or the only one) in the sequenceconsumer
- the callback- Throws:
java.io.UncheckedIOException
- in case of a decoding errorjava.lang.NullPointerException
- if either headerBlock or consumer are null
-
-