public abstract class UTF8Convert
extends java.lang.Object
The difference between utf8 and pseudo-utf8 is the special treatment of null. In utf8, null is encoded as a single byte directly, whereas in pseudo-utf8, it is encoded as a two-byte sequence. See the JVM spec for more information.
| Constructor and Description |
|---|
UTF8Convert() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
check(byte[] bytes)
Check whether the given sequence of bytes is valid (pseudo-)utf8.
|
static java.lang.String |
fromUTF8(byte[] utf8)
Convert the given sequence of (pseudo-)utf8 formatted bytes into a String.
|
static java.lang.String |
fromUTF8(ImmutableByteArray s) |
static byte[] |
toUTF8(java.lang.String s)
Convert the given String into a sequence of (pseudo-)utf8 formatted bytes.
|
static int |
utfLength(java.lang.String s)
Returns the length of a string's UTF encoded form.
|
public static java.lang.String fromUTF8(byte[] utf8)
throws java.io.UTFDataFormatException
The acceptable input formats are controlled by the STRICTLY_CHECK_FORMAT, ALLOW_NORMAL_UTF8, and ALLOW_PSEUDO_UTF8 flags.
utf8 - (pseudo-)utf8 byte arrayjava.io.UTFDataFormatException - if the (pseudo-)utf8 byte array is not valid (pseudo-)utf8java.lang.IllegalArgumentException - if utf8 is nullpublic static byte[] toUTF8(java.lang.String s)
The output format is controlled by the WRITE_PSEUDO_UTF8 flag.
s - String to convertjava.lang.IllegalArgumentException - if s is nullpublic static int utfLength(java.lang.String s)
java.lang.IllegalArgumentException - if s is nullpublic static boolean check(byte[] bytes)
bytes - byte array to checkjava.lang.IllegalArgumentException - if bytes is nullpublic static java.lang.String fromUTF8(ImmutableByteArray s)