boolean nextChar(iteratedChar it, CharsetDetector det) {
            it.error = false;
            int firstByte = 0;
            int secondByte = 0;
            int thirdByte = 0;
            int fourthByte = 0;

            buildChar:
            {
                firstByte = it.charValue = it.nextByte(det);

                if (firstByte < 0) {
                    // Ran off the end of the input data
                    it.done = true;
                    break buildChar;
                }

                if (firstByte <= 0x80) {
                    // single byte char
                    break buildChar;
                }

                secondByte = it.nextByte(det);
                it.charValue = (it.charValue << 8) | secondByte;

                if (firstByte >= 0x81 && firstByte <= 0xFE) {
                    // Two byte Char
                    if ((secondByte >= 0x40 && secondByte <= 0x7E) ||
                            (secondByte >= 80 && secondByte <= 0xFE)) {
                        break buildChar;
                    }

                    // Four byte char
                    if (secondByte >= 0x30 && secondByte <= 0x39) {
                        thirdByte = it.nextByte(det);

                        if (thirdByte >= 0x81 && thirdByte <= 0xFE) {
                            fourthByte = it.nextByte(det);

                            if (fourthByte >= 0x30 && fourthByte <= 0x39) {
                                it.charValue = (it.charValue << 16) | (thirdByte << 8) | fourthByte;
                                break buildChar;
                            }
                        }
                    }

                    it.error = true;
                    break buildChar;
                }
            }

            return (it.done == false);
        }
GB-18030 recognizer. Uses simplified Chinese statistics.
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-text-module/src/main/java/org/apache/tika/parser/txt/CharsetRecog_mbcs.java