/** puts as utf-8 string */ protected int _put(String str) { final int len = str.length(); int total = 0; for (int i = 0; i < len; ) { int c = Character.codePointAt(str, i); if (c < 0x80) { _buf.write((byte) c); total += 1; } else if (c < 0x800) { _buf.write((byte) (0xc0 + (c >> 6))); _buf.write((byte) (0x80 + (c & 0x3f))); total += 2; } else if (c < 0x10000) { _buf.write((byte) (0xe0 + (c >> 12))); _buf.write((byte) (0x80 + ((c >> 6) & 0x3f))); _buf.write((byte) (0x80 + (c & 0x3f))); total += 3; } else { _buf.write((byte) (0xf0 + (c >> 18))); _buf.write((byte) (0x80 + ((c >> 12) & 0x3f))); _buf.write((byte) (0x80 + ((c >> 6) & 0x3f))); _buf.write((byte) (0x80 + (c & 0x3f))); total += 4; } i += Character.charCount(c); } _buf.write((byte) 0); total++; return total; }