public static int toBytes(String str, int srcOffset, int srcLen, byte[] dst, int dstOffset) {
        CharBuffer c = CharBuffer.wrap(str, srcOffset, srcOffset + srcLen);
        ByteBuffer b = UTF_8.encode(c);
        int encoded = b.remaining();
        b.get(dst, dstOffset, encoded);
        return encoded;
    }
Direct encoding of a String into an array.

@param str
           string to encode
@param srcOffset
           index of first character in string to encode
@param srcLen
           number of characters in string to encode
@param dst
           destination for encoded data
@param dstOffset
           index of first position to write data
@return the number of bytes written to the array.
vespajlib/src/main/java/com/yahoo/text/Utf8.java