public static int encode(int codepoint, OutputStream destination) throws IOException {
        byte firstByte = firstByte(codepoint);
        int toWrite = codePointAsUtf8Length(codepoint);
        int leftToWrite = toWrite - 1;
        destination.write(firstByte);
        while (leftToWrite-- > 0) {
            destination.write(trailingOctet(codepoint, leftToWrite));
        }
        return toWrite;
    }
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