Java Utililty Methods UTF8

List of utility methods to do UTF8

Description

The list of methods to do UTF8 are organized into topic(s).

Method

Stringutf8BytesToString(byte[] bytes, int start, int length)
Converts an array of UTF-8 bytes into a string.
if (tempBuffer == null || tempBuffer.length < length) {
    tempBuffer = new char[length];
char[] chars = tempBuffer;
int outAt = 0;
for (int at = start; length > 0; ) {
    int v0 = bytes[at] & 0xFF;
    char out;
...
Stringutf8BytesToString(final byte[] in_utf8Bytes)
Converts UTF-8 byte array to a string in UTF-16 format.
return new String(in_utf8Bytes, UTF8_CHARSET);
intutf8CharLen(byte byte1)
utf Char Len
if ((byte1 & 0x80) == 0) {
    return 1;
} else if ((byte1 & 0xE0) == 0xC0) {
    return 2;
} else if ((byte1 & 0xF0) == 0xE0) {
    return 3;
} else if ((byte1 & 0xF8) == 0xF0) {
    return 4;
...
byte[]UTF8GetBytes(final String value)
Encodes all the characters in the specified string into a sequence of UTF-8 bytes.
final byte[] result = value.getBytes(UTF8);
return result;
StringUTF8GetString(final byte[] bytes, final int index, final int count)
Decodes a range of bytes from a byte array into a string.
final String result = new String(bytes, index, count, UTF8);
return result;
intutf8Len(byte b)
utf Len
int num = b & 255;
if (num < 0x80)
    return 1;
if (num < 0xe0)
    return 2;
if (num < 0xf0)
    return 3;
if (num < 0xf8)
...
intutf8Length(byte[] buffer, int str, int len)
utf Length
final int last = str + len;
int counter = 0;
while (str < last) {
    final int bt = buffer[str];
    if ((bt & 0x80) == 0) {
        ++str;
    } else if ((bt & 0x20) == 0) {
        str += 2;
...
Stringutf8Replace(String str)
utf Replace
if (str != null) {
    return str.replace(FULL_MINUS, HALF_MINUS);
return null;
Stringutf8SafeCEscape(String src)
utf Safe C Escape
char[] srcArr = src.toCharArray();
int destLength = srcArr.length * 4;
char[] dest = new char[destLength];
int len = cEscapeInternal(srcArr, dest, false, true);
if (len > 0) {
    return new String(dest, 0, len);
throw new IllegalStateException();
...
Stringutf8String(String... strs)
utf String
return new String(String.join("", strs).getBytes(), Charset.defaultCharset());