Package com.amazon.ion.impl.bin.utf8
Class Utf8StringDecoder
- java.lang.Object
-
- com.amazon.ion.impl.bin.utf8.Utf8StringDecoder
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class Utf8StringDecoder extends java.lang.ObjectDecodesStrings from UTF-8. Instances of this class are reusable but are NOT threadsafe. Instances are vended byPool.getOrCreate(). Users are expected to callCloseable.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Attempts to return this instance to the pool with which it is associated, if any.java.lang.Stringdecode(java.nio.ByteBuffer utf8InputBuffer, int numberOfBytes)Decodes the given number of UTF-8 bytes from the given ByteBuffer into a Java String.java.lang.StringfinishDecode()Finishes decoding and returns the resulting String.voidpartialDecode(java.nio.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 Detail
-
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
public void partialDecode(java.nio.ByteBuffer utf8InputBuffer, boolean endOfInput)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
public java.lang.String finishDecode()
Finishes decoding and returns the resulting String.- Returns:
- the decoded Java String.
-
decode
public 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.- 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 interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
-