public int read() throws IOException {
  int c=fSurrogate;
  if (fSurrogate == -1) {
    int index=0;
    int b0=index == fOffset ? fInputStream.read() : fBuffer[index++] & 0x00FF;
    if (b0 == -1) {
      return -1;
    }
    if (b0 < 0x80) {
      c=(char)b0;
    }
 else     if ((b0 & 0xE0) == 0xC0) {
      int b1=index == fOffset ? fInputStream.read() : fBuffer[index++] & 0x00FF;
      if (b1 == -1) {
        expectedByte(2,2);
      }
      if ((b1 & 0xC0) != 0x80) {
        invalidByte(2,2,b1);
      }
      c=((b0 << 6) & 0x07C0) | (b1 & 0x003F);
    }
 else     if ((b0 & 0xF0) == 0xE0) {
      int b1=index == fOffset ? fInputStream.read() : fBuffer[index++] & 0x00FF;
      if (b1 == -1) {
        expectedByte(2,3);
      }
      if ((b1 & 0xC0) != 0x80) {
        invalidByte(2,3,b1);
      }
      int b2=index == fOffset ? fInputStream.read() : fBuffer[index++] & 0x00FF;
      if (b2 == -1) {
        expectedByte(3,3);
      }
      if ((b2 & 0xC0) != 0x80) {
        invalidByte(3,3,b2);
      }
      c=((b0 << 12) & 0xF000) | ((b1 << 6) & 0x0FC0) | (b2 & 0x003F);
    }
 else     if ((b0 & 0xF8) == 0xF0) {
      int b1=index == fOffset ? fInputStream.read() : fBuffer[index++] & 0x00FF;
      if (b1 == -1) {
        expectedByte(2,4);
      }
      if ((b1 & 0xC0) != 0x80) {
        invalidByte(2,3,b1);
      }
      int b2=index == fOffset ? fInputStream.read() : fBuffer[index++] & 0x00FF;
      if (b2 == -1) {
        expectedByte(3,4);
      }
      if ((b2 & 0xC0) != 0x80) {
        invalidByte(3,3,b2);
      }
      int b3=index == fOffset ? fInputStream.read() : fBuffer[index++] & 0x00FF;
      if (b3 == -1) {
        expectedByte(4,4);
      }
      if ((b3 & 0xC0) != 0x80) {
        invalidByte(4,4,b3);
      }
      int uuuuu=((b0 << 2) & 0x001C) | ((b1 >> 4) & 0x0003);
      if (uuuuu > 0x10) {
        invalidSurrogate(uuuuu);
      }
      int wwww=uuuuu - 1;
      int hs=0xD800 | ((wwww << 6) & 0x03C0) | ((b1 << 2) & 0x003C)| ((b2 >> 4) & 0x0003);
      int ls=0xDC00 | ((b2 << 6) & 0x03C0) | (b3 & 0x003F);
      c=hs;
      fSurrogate=ls;
    }
 else {
      invalidByte(1,1,b0);
    }
  }
 else {
    fSurrogate=-1;
  }
  return c;
}

public int read ( ) throws IOException { int c = fSurrogate ; if ( fSurrogate == - 1 ) { int index = 0 ; int b0 = index == fOffset ? fInputStream . read ( ) : fBuffer [ index ++ ] & 0x00FF ; if ( b0 == - 1 ) { return - 1 ; } if ( b0 < 0x80 ) { c = ( char ) b0 ; } else if ( ( b0 & 0xE0 ) == 0xC0 ) { int b1 = index == fOffset ? fInputStream . read ( ) : fBuffer [ index ++ ] & 0x00FF ; if ( b1 == - 1 ) { expectedByte ( 2 , 2 ) ; } if ( ( b1 & 0xC0 ) != 0x80 ) { invalidByte ( 2 , 2 , b1 ) ; } c = ( ( b0 << 6 ) & 0x07C0 ) | ( b1 & 0x003F ) ; } else if ( ( b0 & 0xF0 ) == 0xE0 ) { int b1 = index == fOffset ? fInputStream . read ( ) : fBuffer [ index ++ ] & 0x00FF ; if ( b1 == - 1 ) { expectedByte ( 2 , 3 ) ; } if ( ( b1 & 0xC0 ) != 0x80 ) { invalidByte ( 2 , 3 , b1 ) ; } int b2 = index == fOffset ? fInputStream . read ( ) : fBuffer [ index ++ ] & 0x00FF ; if ( b2 == - 1 ) { expectedByte ( 3 , 3 ) ; } if ( ( b2 & 0xC0 ) != 0x80 ) { invalidByte ( 3 , 3 , b2 ) ; } c = ( ( b0 << 12 ) & 0xF000 ) | ( ( b1 << 6 ) & 0x0FC0 ) | ( b2 & 0x003F ) ; } else if ( ( b0 & 0xF8 ) == 0xF0 ) { int b1 = index == fOffset ? fInputStream . read ( ) : fBuffer [ index ++ ] & 0x00FF ; if ( b1 == - 1 ) { expectedByte ( 2 , 4 ) ; } if ( ( b1 & 0xC0 ) != 0x80 ) { invalidByte ( 2 , 3 , b1 ) ; } int b2 = index == fOffset ? fInputStream . read ( ) : fBuffer [ index ++ ] & 0x00FF ; if ( b2 == - 1 ) { expectedByte ( 3 , 4 ) ; } if ( ( b2 & 0xC0 ) != 0x80 ) { invalidByte ( 3 , 3 , b2 ) ; } int b3 = index == fOffset ? fInputStream . read ( ) : fBuffer [ index ++ ] & 0x00FF ; if ( b3 == - 1 ) { expectedByte ( 4 , 4 ) ; } if ( ( b3 & 0xC0 ) != 0x80 ) { invalidByte ( 4 , 4 , b3 ) ; } int uuuuu = ( ( b0 << 2 ) & 0x001C ) | ( ( b1 > > 4 ) & 0x0003 ) ; if ( uuuuu > 0x10 ) { invalidSurrogate ( uuuuu ) ; } int wwww = uuuuu - 1 ; int hs = 0xD800 | ( ( wwww << 6 ) & 0x03C0 ) | ( ( b1 << 2 ) & 0x003C ) | ( ( b2 > > 4 ) & 0x0003 ) ; int ls = 0xDC00 | ( ( b2 << 6 ) & 0x03C0 ) | ( b3 & 0x003F ) ; c = hs ; fSurrogate = ls ; } else { invalidByte ( 1 , 1 , b0 ) ; } } else { fSurrogate = - 1 ; } return c ; }
read a single character . this method will block until a character is available , an i / o error occurs , or the end of the stream is reached . < p > subclasses that intend to support efficient single - character input should override this method .
