@Override
    public int read() throws IOException {
        if (pending != '\u0000') {
            char rv = pending;
            pending = '\u0000';
            return rv;
        }
        int byteVal = 0;
        int codePoint = 0;
        int c = delegate.read();
        int trailBytes = 0;
        if (c == -1) {
            return -1;
        } if (c == '%') {
            byteVal = readHexByte();
            if (byteVal < 0x80) {
                return byteVal;
            } else if ((0xE0 & byteVal) == 0xC0) {
                trailBytes = 1;
                codePoint = byteVal & 0x1F;
            } else if ((0xF0 & byteVal) == 0xE0) {
                trailBytes = 2;                
                codePoint = byteVal & 0x0F;
            } else if ((0xF8 & byteVal) == 0xF0) {
                trailBytes = 3;
                codePoint = byteVal & 0x07;
            } else {
                throw new MalformedURLException("Percent escape decodes to a byte that is not a valid UTF-8 lead byte.");                
            }
            for (int i = 0; i < trailBytes; i++) {
                byteVal = readPercentHexByte();
                if ((0xC0 & byteVal) == 0x80) {
                    codePoint = (codePoint << 6) | (byteVal & 0x3F);
                } else {
                    throw new MalformedURLException("Percent escape decodes to a byte that is not a valid UTF-8 trail byte.");                                    
                }
            }
            switch (trailBytes) {
                case 3:
                    if (codePoint <= 0xFFFF) {
                        throw new MalformedURLException("Non-shortest form UTF-8 percent escape sequence.");                                                            
                    } else {
                        int rv = (0xD7C0 + (codePoint >> 10));
                        pending = (char) (0xDC00 + (codePoint & 0x3FF));
                        return rv;
                    }
                case 2:
                    if (codePoint <= 0x07FF) {
                        throw new MalformedURLException("Non-shortest form UTF-8 percent escape sequence.");                                                                                    
                    } else {
                        return codePoint;
                    }
                default:
                    if (codePoint <= 0x007F) {
                        throw new MalformedURLException("Non-shortest form UTF-8 percent escape sequence.");                                                                                    
                    } else {
                        return codePoint;
                    }                    
            }
        } else {
            return c;
        }
    }
@ Override public int read ( ) throws IOException { if ( pending != '' ) { char rv = pending ; pending = '' ; return rv ; } int byteVal = 0 ; int codePoint = 0 ; int c = delegate . read ( ) ; int trailBytes = 0 ; if ( c == - 1 ) { return - 1 ; } if ( c == '%' ) { byteVal = readHexByte ( ) ; if ( byteVal < 0x80 ) { return byteVal ; } else if ( ( 0xE0 & byteVal ) == 0xC0 ) { trailBytes = 1 ; codePoint = byteVal & 0x1F ; } else if ( ( 0xF0 & byteVal ) == 0xE0 ) { trailBytes = 2 ; codePoint = byteVal & 0x0F ; } else if ( ( 0xF8 & byteVal ) == 0xF0 ) { trailBytes = 3 ; codePoint = byteVal & 0x07 ; } else { throw new MalformedURLException ( "Percent escape decodes to a byte that is not a valid UTF-8 lead byte." ) ; } for ( int i = 0 ; i < trailBytes ; i ++ ) { byteVal = readPercentHexByte ( ) ; if ( ( 0xC0 & byteVal ) == 0x80 ) { codePoint = ( codePoint << 6 ) | ( byteVal & 0x3F ) ; } else { throw new MalformedURLException ( "Percent escape decodes to a byte that is not a valid UTF-8 trail byte." ) ; } } switch ( trailBytes ) { case 3 : if ( codePoint <= 0xFFFF ) { throw new MalformedURLException ( "Non-shortest form UTF-8 percent escape sequence." ) ; } else { int rv = ( 0xD7C0 + ( codePoint > > 10 ) ) ; pending = ( char ) ( 0xDC00 + ( codePoint & 0x3FF ) ) ; return rv ; } case 2 : if ( codePoint <= 0x07FF ) { throw new MalformedURLException ( "Non-shortest form UTF-8 percent escape sequence." ) ; } else { return codePoint ; } default : if ( codePoint <= 0x007F ) { throw new MalformedURLException ( "Non-shortest form UTF-8 percent escape sequence." ) ; } else { return codePoint ; } } } else { return c ; } }
@see java.io.Reader#read()