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

public Class Utf8StringEncoder

extends Poolable<Utf8StringEncoder>
Class Inheritance
Imports
java.nio.ByteBuffer, .CharBuffer, java.nio.charset.Charset, .CharsetEncoder, .CoderResult

Encodes Strings to UTF-8. Instances of this class are reusable but are NOT threadsafe. Instances are vended by Utf8StringEncoderPool#getOrCreate(). encode(String) can be called any number of times. Users are expected to call close() when the encoder is no longer needed.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Utf8StringEncoder.Result

Represents the result of a Utf8StringEncoder#encode(String) operation.

Field Summary

Modifier and TypeField and Description
pack-priv final char[]
pack-priv final CharBuffer
private static final int
pack-priv final CharsetEncoder
pack-priv final ByteBuffer

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Utf8StringEncoder.Result

Returns:

A Result containing a byte array of UTF-8 bytes and encoded length.
encode
(String
A Java String to encode as UTF8 bytes.
text
)

Encodes the provided String's text to UTF-8.

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

Field Detail

charArrayback to summary
pack-priv final char[] charArray
charBufferback to summary
pack-priv final CharBuffer charBuffer
SMALL_STRING_SIZEback to summary
private static final int SMALL_STRING_SIZE
utf8Encoderback to summary
pack-priv final CharsetEncoder utf8Encoder
utf8EncodingBufferback to summary
pack-priv final ByteBuffer utf8EncodingBuffer

Constructor Detail

Utf8StringEncoderback to summary
pack-priv Utf8StringEncoder(Pool<Utf8StringEncoder> pool)

Method Detail

encodeback to summary
public Utf8StringEncoder.Result encode(String text)

Encodes the provided String's text to UTF-8. Unlike String#getBytes(Charset), this method will not silently replace characters that cannot be encoded with a substitute character. Instead, it will throw an IllegalArgumentException. Some resources in the returned Result may be reused across calls to this method. Consequently, callers should use the Result and discard it immediately.

Parameters
text:String

A Java String to encode as UTF8 bytes.

Returns:Utf8StringEncoder.Result

A Result containing a byte array of UTF-8 bytes and encoded length.

Exceptions
IllegalArgumentException:
if the String cannot be encoded as UTF-8.
com.amazon.ion.impl.bin.utf8 back to summary

public Class Utf8StringEncoder.Result

extends Object
Class Inheritance

Represents the result of a Utf8StringEncoder#encode(String) operation.

Field Summary

Modifier and TypeField and Description
private final byte[]
private final int

Constructor Summary

AccessConstructor and Description
public
Result(int encodedLength, byte[] buffer)

Method Summary

Modifier and TypeMethod and Description
public byte[]

Returns:

the buffer containing UTF-8 bytes.
getBuffer
()

Returns a byte array containing the encoded UTF-8 bytes starting at index 0.

public int

Returns:

the number of encoded bytes in the array returned by getBuffer().
getEncodedLength
()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferback to summary
private final byte[] buffer
encodedLengthback to summary
private final int encodedLength

Constructor Detail

Resultback to summary
public Result(int encodedLength, byte[] buffer)

Method Detail

getBufferback to summary
public byte[] getBuffer()

Returns a byte array containing the encoded UTF-8 bytes starting at index 0. This byte array is NOT guaranteed to be the same length as the data it contains. Callers must use getEncodedLength() to determine the number of bytes that should be read from the byte array.

Returns:byte[]

the buffer containing UTF-8 bytes.

getEncodedLengthback to summary
public int getEncodedLength()
Returns:int

the number of encoded bytes in the array returned by getBuffer().