code: public int write(OutputStreamWithBuffer os, char []cbuf, int off, int len)
      throws IOException
    {
      for (int i = 0; i < len; i++) {
        char ch = cbuf[off + i];
  
        if (ch < 0x80)
          os.write(ch);
        else {
          os.write('\\');
          os.write('u');
  
          int b = (ch >> 12) & 0xf;
          os.write(b < 10 ? b + '0' : b + 'a' - 10);
          b = (ch >> 8) & 0xf;
          os.write(b < 10 ? b + '0' : b + 'a' - 10);
          b = (ch >> 4) & 0xf;
          os.write(b < 10 ? b + '0' : b + 'a' - 10);
          b = ch & 0xf;
          os.write(b < 10 ? b + '0' : b + 'a' - 10);
        }
      }
      
      return len;
    }
docs: Writes into a character buffer using the correct encoding.
  
  @param cbuf character array with the data to write.
  @param off starting offset into the character array.
  @param len the number of characters to write.