class TextUtil {

    public static byte[] toUtf8(String string) {
        ByteBuffer buffer;
        try {
            buffer = Text.encode(string, false);
        } catch (CharacterCodingException cce) {
            throw new IllegalArgumentException(cce);
        }
        byte[] bytes = new byte[buffer.limit()];
        System.arraycopy(buffer.array(), 0, bytes, 0, bytes.length);
        return bytes;
    }

}