public class Utf8StringDecoder
extends java.lang.Object
Strings from UTF-8. Instances of this class are reusable but are NOT threadsafe.
Instances are vended by Pool.getOrCreate().
Users are expected to call close() when the decoder is no longer needed.
There are two ways of using this class:
decode(ByteBuffer, int) to decode the requested number of bytes from the given ByteBuffer in
a single step. Or,prepareDecode(int) to prepare the decoder to decode the requested number of bytes.partialDecode(ByteBuffer, boolean) to decode the available bytes from the byte buffer. This may
be repeated as more bytes are made available in the ByteBuffer, which is the caller's responsibility.finishDecode() to finish decoding and return the resulting String.decode(ByteBuffer, int) must not be called between calls to prepareDecode(int) and
finishDecode().
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Attempts to return this instance to the pool with which it is associated, if any.
|
java.lang.String |
decode(java.nio.ByteBuffer utf8InputBuffer,
int numberOfBytes)
Decodes the given number of UTF-8 bytes from the given ByteBuffer into a Java String.
|
java.lang.String |
finishDecode()
Finishes decoding and returns the resulting String.
|
void |
partialDecode(java.nio.ByteBuffer utf8InputBuffer,
boolean endOfInput)
Decodes the available bytes from the given ByteBuffer.
|
void |
prepareDecode(int numberOfBytes)
Prepares the decoder to decode the given number of UTF-8 bytes.
|
public void prepareDecode(int numberOfBytes)
numberOfBytes - the number of bytes to decode.public void partialDecode(java.nio.ByteBuffer utf8InputBuffer,
boolean endOfInput)
utf8InputBuffer - a ByteBuffer containing UTF-8 bytes.endOfInput - true if the end of the UTF-8 sequence is expected to occur in the buffer; otherwise, false.public java.lang.String finishDecode()
public java.lang.String decode(java.nio.ByteBuffer utf8InputBuffer,
int numberOfBytes)
utf8InputBuffer - a ByteBuffer containing UTF-8 bytes.numberOfBytes - the number of bytes from the utf8InputBuffer to decode.public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseable