Package com.amazon.ion.impl.bin.utf8
Class Utf8StringEncoder
java.lang.Object
com.amazon.ion.impl.bin.utf8.Utf8StringEncoder
- All Implemented Interfaces:
Closeable,AutoCloseable
Encodes
Strings to UTF-8. Instances of this class are reusable but are NOT threadsafe.
Instances are vended by Pool.getOrCreate().
encode(String) can be called any number of times. Users are expected to call Closeable.close() when
the encoder is no longer needed.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents the result of aencode(String)operation. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Attempts to return this instance to the pool with which it is associated, if any.Encodes the provided String's text to UTF-8.
-
Method Details
-
encode
Encodes the provided String's text to UTF-8. UnlikeString.getBytes(Charset), this method will not silently replace characters that cannot be encoded with a substitute character. Instead, it will throw anIllegalArgumentException. Some resources in the returnedUtf8StringEncoder.Resultmay be reused across calls to this method. Consequently, callers should use the Result and discard it immediately.- Parameters:
text- A Java String to encode as UTF8 bytes.- Returns:
- A
Utf8StringEncoder.Resultcontaining a byte array of UTF-8 bytes and encoded length. - Throws:
IllegalArgumentException- if the String cannot be encoded as UTF-8.
-
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
-