in computer-api/src/main/java/org/apache/hugegraph/computer/core/util/CoderUtil.java [82:156]
public static String decode(byte[] bytes, int start, int length) {
// Note that this code is mostly copied from DataInputStream
char[] chars = new char[length];
int c;
int char2;
int char3;
int count = start;
int charIndex = 0;
while (count < length) {
c = (int) bytes[count] & 0xff;
if (c > 127) {
break;
}
count++;
chars[charIndex++] = (char) c;
}
while (count < length) {
c = (int) bytes[count] & 0xff;
switch (c >> 4) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
// 0xxxxxxx
count++;
chars[charIndex++] = (char) c;
break;
case 12:
case 13:
// 110x xxxx 10xx xxxx
count += 2;
if (count > length) {
throw new ComputerException(
"Malformed input: partial character at end");
}
char2 = (int) bytes[count - 1];
if ((char2 & 0xC0) != 0x80) {
throw new ComputerException(
"Malformed input around byte " + count);
}
chars[charIndex++] = (char) (((c & 0x1F) << 6) |
(char2 & 0x3F));
break;
case 14:
// 1110 xxxx 10xx xxxx 10xx xxxx
count += 3;
if (count > length) {
throw new ComputerException(
"Malformed input: partial character at end");
}
char2 = bytes[count - 2];
char3 = bytes[count - 1];
if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) {
throw new ComputerException(
"Malformed input around byte " + (count - 1));
}
chars[charIndex++] = (char) (((c & 0x0F) << 12) |
((char2 & 0x3F) << 6) |
((char3 & 0x3F) << 0));
break;
default:
// 10xx xxxx, 1111 xxxx
throw new ComputerException(
"Malformed input around byte " + count);
}
}
// The number of chars produced may be less than len
return new String(chars, 0, charIndex);
}