privatestaticvoid isValidUTF8(byte[] bytes)throws IllegalStateException...{ int countToValidate =0; for (int i =0; i < bytes.length && countToValidate ==0; i++) ...{ int b = bytes[i]; if (b >0) ...{ continue;// ascii char } debugInt(b, "cur"); while (((b >>6) &0x3) ==0x3)...{// check the 11 pattern countToValidate++; b = (b <<1); debugInt(b, "cur_c"); i++; if (i>bytes.length-1) break; int next = bytes[i] &0xff; debugInt(next, "next"); if ((next >=0x80&& next <0xc0)) ...{ countToValidate--; } } } if (countToValidate >0) thrownew IllegalStateException(); }
private static void isValidUTF8(byte[] bytes)throws IllegalStateException...{ int countToValidate = 0; for (int i = 0; i bytes.length && countToValidate == 0; i++) ...{ int