public class Utf8StringEncoder
extends java.lang.Object
String
s 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 close()
when
the encoder is no longer needed.Modifier and Type | Class and Description |
---|---|
static class |
Utf8StringEncoder.Result
Represents the result of a
encode(String) operation. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Attempts to return this instance to the pool with which it is associated, if any.
|
Utf8StringEncoder.Result |
encode(java.lang.String text)
Encodes the provided String's text to UTF-8.
|
public Utf8StringEncoder.Result encode(java.lang.String text)
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 Utf8StringEncoder.Result
may be reused across calls to this method. Consequently,
callers should use the Result and discard it immediately.text
- A Java String to encode as UTF8 bytes.Utf8StringEncoder.Result
containing a byte array of UTF-8 bytes and encoded length.java.lang.IllegalArgumentException
- if the String cannot be encoded as UTF-8.public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable