private static byte firstByte(int codepoint) {
        if (codepoint < 0x800) {
            if (codepoint < 0x80) {
                return (byte) codepoint;
            } else {
                return (byte) (0xC0 | codepoint >> 6);
            }
        } else {
            if (codepoint < 0x10000) {
                return (byte) (0xE0 | codepoint >> 12);
            } else {
                return (byte) (0xF0 | codepoint >> 18);
            }
        }

    }
Encode a valid Unicode codepoint as a sequence of UTF-8 bytes into an
OutputStream.

@param codepoint
           Unicode codepoint to encode
@param destination
           buffer to write into
@return number of bytes written
@throws IOException
            propagated from stream
vespajlib/src/main/java/com/yahoo/text/Utf8.java