public int readUTF8Int(ByteData raw) throws IOException {
        int val;
        int v = 0;
        int x;
        int i;
        x = readRawUInt(8);
        if (raw != null) raw.append((byte) x);
        if ((x & 0x80) == 0) { // 0xxxxxxx
            v = x;
            i = 0;
        } else if (((x & 0xC0) != 0) && ((x & 0x20) == 0)) { // 110xxxxx
            v = x & 0x1F;
            i = 1;
        } else if (((x & 0xE0) != 0) && ((x & 0x10) == 0)) { // 1110xxxx
            v = x & 0x0F;
            i = 2;
        } else if (((x & 0xF0) != 0) && ((x & 0x08) == 0)) { // 11110xxx
            v = x & 0x07;
            i = 3;
        } else if (((x & 0xF8) != 0) && ((x & 0x04) == 0)) { // 111110xx
            v = x & 0x03;
            i = 4;
        } else if (((x & 0xFC) != 0) && ((x & 0x02) == 0)) { // 1111110x
            v = x & 0x01;
            i = 5;
        } else {
            val = 0xffffffff;
            return val;
        }
        for (; i > 0; i--) {
            x = peekRawUInt(8);
            if (((x & 0x80) == 0) || ((x & 0x40) != 0)) { // 10xxxxxx
                val = 0xffffffff;
                return val;
            }
            x = readRawUInt(8);
            if (raw != null)
                raw.append((byte) x);
            v <<= 6;
            v |= (x & 0x3F);
        }
        val = v;
        return val;
    }
public int readUTF8Int ( ByteData raw ) throws IOException { int val ; int v = 0 ; int x ; int i ; x = readRawUInt ( 8 ) ; if ( raw != null ) raw . append ( ( byte ) x ) ; if ( ( x & 0x80 ) == 0 ) { v = x ; i = 0 ; } else if ( ( ( x & 0xC0 ) != 0 ) && ( ( x & 0x20 ) == 0 ) ) { v = x & 0x1F ; i = 1 ; } else if ( ( ( x & 0xE0 ) != 0 ) && ( ( x & 0x10 ) == 0 ) ) { v = x & 0x0F ; i = 2 ; } else if ( ( ( x & 0xF0 ) != 0 ) && ( ( x & 0x08 ) == 0 ) ) { v = x & 0x07 ; i = 3 ; } else if ( ( ( x & 0xF8 ) != 0 ) && ( ( x & 0x04 ) == 0 ) ) { v = x & 0x03 ; i = 4 ; } else if ( ( ( x & 0xFC ) != 0 ) && ( ( x & 0x02 ) == 0 ) ) { v = x & 0x01 ; i = 5 ; } else { val = 0xffffffff ; return val ; } for ( ; i > 0 ; i -- ) { x = peekRawUInt ( 8 ) ; if ( ( ( x & 0x80 ) == 0 ) || ( ( x & 0x40 ) != 0 ) ) { val = 0xffffffff ; return val ; } x = readRawUInt ( 8 ) ; if ( raw != null ) raw . append ( ( byte ) x ) ; v <<= 6 ; v |= ( x & 0x3F ) ; } val = v ; return val ; }
read UTF8 integer.
on return, if *val == 0xffffffff then the utf-8 sequence was invalid, but
the return value will be true
@param raw   The raw bytes read (output). If null, no bytes are returned
@return      The integer read
@throws IOException  Thrown if error reading input stream