publicbooleanvalidUtf8(int[] data) { inti=0; while (i < data.length) { intnum= data[i]; if (isFourByte(num)) { booleanok= isFollowByte(data, i + 1) && isFollowByte(data, i + 2) && isFollowByte(data, i + 3); if (!ok) { returnfalse; }
i += 4; continue; }
if (isThreeByte(num)) { booleanok= isFollowByte(data, i + 1) && isFollowByte(data, i + 2); if (!ok) { returnfalse; }
i += 3; continue; }
if (isTwoByte(num)) { booleanok= isFollowByte(data, i + 1); if (!ok) { returnfalse; }
i += 2; continue; }
if (isOneByte(num)) { i++; continue; }
returnfalse; }
returntrue; }
privatebooleanisOneByte(int num) { return num >= ONE_BYTE_START && num <= ONE_BYTE_END; }
privatebooleanisTwoByte(int num) { return num >= TWO_BYTE_START && num <= TWO_BYTE_END; }
privatebooleanisThreeByte(int num) { return num >= THREE_BYTE_START && num <= THREE_BYTE_END; }
privatebooleanisFourByte(int num) { return num >= FOUR_BYTE_START && num <= FOUR_BYTE_END; }
privatebooleanisFollowByte(int[] data, int i) { return i < data.length && data[i] >= FOLLOW_BYTE_START && data[i] <= FOLLOW_BYTE_END; } }