Package com.amazon.ion.impl.bin.utf8
Class Utf8StringDecoder
java.lang.Object
com.amazon.ion.impl.bin.utf8.Utf8StringDecoder
- All Implemented Interfaces:
Closeable,AutoCloseable
Decodes
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 Closeable.close() when the decoder is no longer needed.
There are two ways of using this class:
- Use
decode(ByteBuffer, int)to decode the requested number of bytes from the given ByteBuffer in a single step. Or, - Use the following sequence of method calls:
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 toprepareDecode(int)andfinishDecode().
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Attempts to return this instance to the pool with which it is associated, if any.decode(ByteBuffer utf8InputBuffer, int numberOfBytes) Decodes the given number of UTF-8 bytes from the given ByteBuffer into a Java String.Finishes decoding and returns the resulting String.voidpartialDecode(ByteBuffer utf8InputBuffer, boolean endOfInput) Decodes the available bytes from the given ByteBuffer.voidprepareDecode(int numberOfBytes) Prepares the decoder to decode the given number of UTF-8 bytes.
-
Method Details
-
prepareDecode
public void prepareDecode(int numberOfBytes) Prepares the decoder to decode the given number of UTF-8 bytes.- Parameters:
numberOfBytes- the number of bytes to decode.
-
partialDecode
Decodes the available bytes from the given ByteBuffer.- Parameters:
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.
-
finishDecode
Finishes decoding and returns the resulting String.- Returns:
- the decoded Java String.
-
decode
Decodes the given number of UTF-8 bytes from the given ByteBuffer into a Java String.- Parameters:
utf8InputBuffer- a ByteBuffer containing UTF-8 bytes.numberOfBytes- the number of bytes from the utf8InputBuffer to decode.- Returns:
- the decoded Java String.
-
close
public void close()Attempts to return this instance to the pool with which it is associated, if any. Do not continue to use this instance after calling this method.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-