sclass UTF8Processor { byte[] buffer = new byte[5]; int count = 0; S processByte(byte nextByte) ctex { buffer[count++] = nextByte; if(count == expectedBytes()) { S result = new S(buffer, 0, count, "UTF-8"); count = 0; return result; } return ""; } int expectedBytes() { int num = buffer[0] & 255; if(num < 0x80) return 1; if(num < 0xe0) return 2; if(num < 0xf0) return 3; if(num < 0xf8) return 4; return 5; } }