Package com.amazon.ion.impl.bin.utf8
Class Utf8StringEncoder
- java.lang.Object
-
- com.amazon.ion.impl.bin.utf8.Utf8StringEncoder
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class Utf8StringEncoder extends java.lang.ObjectEncodesStrings to UTF-8. Instances of this class are reusable but are NOT threadsafe. Instances are vended byPool.getOrCreate().encode(String)can be called any number of times. Users are expected to callCloseable.close()when the encoder is no longer needed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUtf8StringEncoder.ResultRepresents the result of aencode(String)operation.
-
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.Utf8StringEncoder.Resultencode(java.lang.String text)Encodes the provided String's text to UTF-8.
-
-
-
Method Detail
-
encode
public Utf8StringEncoder.Result encode(java.lang.String text)
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:
java.lang.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 interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
-