@Override public int read(char ch[],int offset,int length) throws IOException {
  int byteLength=length << ((fEncoding >= 4) ? 2 : 1);
  if (byteLength > fBuffer.length) {
    byteLength=fBuffer.length;
  }
  int count=fInputStream.read(fBuffer,0,byteLength);
  if (count == -1)   return -1;
  if (fEncoding >= 4) {
    int numToRead=(4 - (count & 3) & 3);
    for (int i=0; i < numToRead; i++) {
      int charRead=fInputStream.read();
      if (charRead == -1) {
        for (int j=i; j < numToRead; j++) {
          fBuffer[count + j]=0;
        }
        break;
      }
      fBuffer[count + i]=(byte)charRead;
    }
    count+=numToRead;
  }
 else {
    int numToRead=count & 1;
    if (numToRead != 0) {
      count++;
      int charRead=fInputStream.read();
      if (charRead == -1) {
        fBuffer[count]=0;
      }
 else {
        fBuffer[count]=(byte)charRead;
      }
    }
  }
  int numChars=count >> ((fEncoding >= 4) ? 2 : 1);
  int curPos=0;
  for (int i=0; i < numChars; i++) {
    int b0=fBuffer[curPos++] & 0xff;
    int b1=fBuffer[curPos++] & 0xff;
    if (fEncoding >= 4) {
      int b2=fBuffer[curPos++] & 0xff;
      int b3=fBuffer[curPos++] & 0xff;
      if (fEncoding == UCS4BE) {
        ch[offset + i]=(char)((b0 << 24) + (b1 << 16) + (b2 << 8)+ b3);
      }
 else {
        ch[offset + i]=(char)((b3 << 24) + (b2 << 16) + (b1 << 8)+ b0);
      }
    }
 else {
      if (fEncoding == UCS2BE) {
        ch[offset + i]=(char)((b0 << 8) + b1);
      }
 else {
        ch[offset + i]=(char)((b1 << 8) + b0);
      }
    }
  }
  return numChars;
}

@ Override public int read ( char ch [ ] , int offset , int length ) throws IOException { int byteLength = length << ( ( fEncoding >= 4 ) ? 2 : 1 ) ; if ( byteLength > fBuffer . length ) { byteLength = fBuffer . length ; } int count = fInputStream . read ( fBuffer , 0 , byteLength ) ; if ( count == - 1 ) return - 1 ; if ( fEncoding >= 4 ) { int numToRead = ( 4 - ( count & 3 ) & 3 ) ; for ( int i = 0 ; i < numToRead ; i ++ ) { int charRead = fInputStream . read ( ) ; if ( charRead == - 1 ) { for ( int j = i ; j < numToRead ; j ++ ) { fBuffer [ count + j ] = 0 ; } break ; } fBuffer [ count + i ] = ( byte ) charRead ; } count += numToRead ; } else { int numToRead = count & 1 ; if ( numToRead != 0 ) { count ++ ; int charRead = fInputStream . read ( ) ; if ( charRead == - 1 ) { fBuffer [ count ] = 0 ; } else { fBuffer [ count ] = ( byte ) charRead ; } } } int numChars = count > > ( ( fEncoding >= 4 ) ? 2 : 1 ) ; int curPos = 0 ; for ( int i = 0 ; i < numChars ; i ++ ) { int b0 = fBuffer [ curPos ++ ] & 0xff ; int b1 = fBuffer [ curPos ++ ] & 0xff ; if ( fEncoding >= 4 ) { int b2 = fBuffer [ curPos ++ ] & 0xff ; int b3 = fBuffer [ curPos ++ ] & 0xff ; if ( fEncoding == UCS4BE ) { ch [ offset + i ] = ( char ) ( ( b0 << 24 ) + ( b1 << 16 ) + ( b2 << 8 ) + b3 ) ; } else { ch [ offset + i ] = ( char ) ( ( b3 << 24 ) + ( b2 << 16 ) + ( b1 << 8 ) + b0 ) ; } } else { if ( fEncoding == UCS2BE ) { ch [ offset + i ] = ( char ) ( ( b0 << 8 ) + b1 ) ; } else { ch [ offset + i ] = ( char ) ( ( b1 << 8 ) + b0 ) ; } } } return numChars ; }
read characters into a portion of an array . this method will block until some input is available , an i / o error occurs , or the end of the stream is reached .
