Top Description Fields Constructors Methods
com.amazon.ion.impl.bin.utf8

public Class Utf8StringDecoder

extends Poolable<Utf8StringDecoder>
Class Inheritance
Imports
com.amazon.ion.IonException, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.Charset, .CharsetDecoder, .CoderResult

Decodes Strings from UTF-8. Instances of this class are reusable but are NOT threadsafe. Instances are vended by Utf8StringDecoderPool#getOrCreate(). Users are expected to call close() when the decoder is no longer needed. There are two ways of using this class:
  1. Use decode(ByteBuffer, int) to decode the requested number of bytes from the given ByteBuffer in a single step. Or,
  2. Use the following sequence of method calls:
    1. prepareDecode(int) to prepare the decoder to decode the requested number of bytes.
    2. 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.
    3. finishDecode() to finish decoding and return the resulting String.
    Note: decode(ByteBuffer, int) must not be called between calls to prepareDecode(int) and finishDecode().

Field Summary

Modifier and TypeField and Description
private final CharBuffer
private static final int
private final CharsetDecoder
private CharBuffer

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the decoded Java String.
decode
(ByteBuffer
a ByteBuffer containing UTF-8 bytes.
utf8InputBuffer
,
int
the number of bytes from the utf8InputBuffer to decode.
numberOfBytes
)

Decodes the given number of UTF-8 bytes from the given ByteBuffer into a Java String.

public String

Returns:

the decoded Java String.
finishDecode
()

Finishes decoding and returns the resulting String.

public void
partialDecode(ByteBuffer
a ByteBuffer containing UTF-8 bytes.
utf8InputBuffer
,
boolean
true if the end of the UTF-8 sequence is expected to occur in the buffer; otherwise, false.
endOfInput
)

Decodes the available bytes from the given ByteBuffer.

public void
prepareDecode(int
the number of bytes to decode.
numberOfBytes
)

Prepares the decoder to decode the given number of UTF-8 bytes.

Inherited from com.amazon.ion.impl.bin.utf8.Poolable:
close

Field Detail

reusableUtf8DecodingBufferback to summary
private final CharBuffer reusableUtf8DecodingBuffer
UTF8_BUFFER_SIZE_IN_BYTESback to summary
private static final int UTF8_BUFFER_SIZE_IN_BYTES
utf8CharsetDecoderback to summary
private final CharsetDecoder utf8CharsetDecoder
utf8DecodingBufferback to summary
private CharBuffer utf8DecodingBuffer

Constructor Detail

Utf8StringDecoderback to summary
pack-priv Utf8StringDecoder(Pool<Utf8StringDecoder> pool)

Method Detail

decodeback to summary
public String decode(ByteBuffer utf8InputBuffer, int numberOfBytes)

Decodes the given number of UTF-8 bytes from the given ByteBuffer into a Java String.

Parameters
utf8InputBuffer:ByteBuffer

a ByteBuffer containing UTF-8 bytes.

numberOfBytes:int

the number of bytes from the utf8InputBuffer to decode.

Returns:String

the decoded Java String.

finishDecodeback to summary
public String finishDecode()

Finishes decoding and returns the resulting String.

Returns:String

the decoded Java String.

partialDecodeback to summary
public void partialDecode(ByteBuffer utf8InputBuffer, boolean endOfInput)

Decodes the available bytes from the given ByteBuffer.

Parameters
utf8InputBuffer:ByteBuffer

a ByteBuffer containing UTF-8 bytes.

endOfInput:boolean

true if the end of the UTF-8 sequence is expected to occur in the buffer; otherwise, false.

prepareDecodeback to summary
public void prepareDecode(int numberOfBytes)

Prepares the decoder to decode the given number of UTF-8 bytes.

Parameters
numberOfBytes:int

the number of bytes to decode.