public final class Utf8 extends Object
Modifier and Type | Method and Description |
---|---|
static int |
maxUtf8ByteLength(int charCount,
boolean zeroTerminate) |
static byte[] |
stringToUtf8(String source,
boolean zeroTerminate) |
static void |
substringToUtf8(ByteBuffer dest,
String source,
int beginIndex,
int endIndex,
boolean zeroTerminate)
Writes an UTF8-encoded string region to a given byte buffer.
|
static int |
utf8Length(String string) |
static int |
utf8Length(String s,
int beginIndex,
int endIndex) |
static String |
utf8ToString(boolean zeroTerminated,
ByteBuffer source)
Converts a byte buffer of UTF-8 data to a String.
|
public static int utf8Length(String string)
public static int utf8Length(String s, int beginIndex, int endIndex)
beginIndex
- first index that is part of the region, inclusiveendIndex
- index at the end of the region, exclusivepublic static int maxUtf8ByteLength(int charCount, boolean zeroTerminate)
public static void substringToUtf8(ByteBuffer dest, String source, int beginIndex, int endIndex, boolean zeroTerminate)
dest
- the byte buffer to write tosource
- the String to be writtenbeginIndex
- first index in source
that is part of the region, inclusiveendIndex
- index in source
at the end of the region, exclusivezeroTerminate
- whether to write a final zero bytepublic static byte[] stringToUtf8(String source, boolean zeroTerminate)
public static String utf8ToString(boolean zeroTerminated, ByteBuffer source) throws CharConversionException
buffer's limit
is converted unless zeroTerminated
is
true
, in which case conversion stops at the first zero byte.zeroTerminated
- if true, then a 0 byte marks the end of the string, and character '\0'
in the input must be encoded as two bytes as opposed to onesource
- the byte buffer to read fromCharConversionException