public void write(byte[] buf,int offset,int length,boolean isEnd) throws IOException {
  int end=offset + length;
  while (offset < end) {
    int ch1=buf[offset++] & 0xff;
    if (ch1 < 0x80)     os.write(ch1);
 else     if ((ch1 & 0xe0) == 0xc0) {
      if (offset >= end)       throw new EOFException("unexpected end of file in utf8 character");
      int ch2=buf[offset++] & 0xff;
      if ((ch2 & 0xc0) != 0x80)       throw new CharConversionException("illegal utf8 encoding");
      os.write(((ch1 & 0x1f) << 6) + (ch2 & 0x3f));
    }
 else     if ((ch1 & 0xf0) == 0xe0) {
      if (offset + 1 >= end)       throw new EOFException("unexpected end of file in utf8 character");
      int ch2=buf[offset++] & 0xff;
      int ch3=buf[offset++] & 0xff;
      if ((ch2 & 0xc0) != 0x80)       throw new CharConversionException("illegal utf8 encoding");
      if ((ch3 & 0xc0) != 0x80)       throw new CharConversionException("illegal utf8 encoding");
      os.write(((ch1 & 0x1f) << 12) + ((ch2 & 0x3f) << 6) + (ch3 & 0x3f));
    }
 else     throw new CharConversionException("illegal utf8 encoding at (" + (int)ch1 + ")");
  }
}

public void write ( byte [ ] buf , int offset , int length , boolean isEnd ) throws IOException { int end = offset + length ; while ( offset < end ) { int ch1 = buf [ offset ++ ] & 0xff ; if ( ch1 < 0x80 ) os . write ( ch1 ) ; else if ( ( ch1 & 0xe0 ) == 0xc0 ) { if ( offset >= end ) throw new EOFException ( "unexpected end of file in utf8 character" ) ; int ch2 = buf [ offset ++ ] & 0xff ; if ( ( ch2 & 0xc0 ) != 0x80 ) throw new CharConversionException ( "illegal utf8 encoding" ) ; os . write ( ( ( ch1 & 0x1f ) << 6 ) + ( ch2 & 0x3f ) ) ; } else if ( ( ch1 & 0xf0 ) == 0xe0 ) { if ( offset + 1 >= end ) throw new EOFException ( "unexpected end of file in utf8 character" ) ; int ch2 = buf [ offset ++ ] & 0xff ; int ch3 = buf [ offset ++ ] & 0xff ; if ( ( ch2 & 0xc0 ) != 0x80 ) throw new CharConversionException ( "illegal utf8 encoding" ) ; if ( ( ch3 & 0xc0 ) != 0x80 ) throw new CharConversionException ( "illegal utf8 encoding" ) ; os . write ( ( ( ch1 & 0x1f ) << 12 ) + ( ( ch2 & 0x3f ) << 6 ) + ( ch3 & 0x3f ) ) ; } else throw new CharConversionException ( "illegal utf8 encoding at (" + ( int ) ch1 + ")" ) ; } }
implementation of the writer write .
