### Question:
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; }  static void textAppend(Text text, String string); static void textAppend(Text text, String string, boolean replaceBadChar); static void textAppend(Text t, long s); static void appendNullByte(Text text); static void textAppendNoNull(Text t, String s); static void textAppendNoNull(Text t, String s, boolean replaceBadChar); static byte[] toUtf8(String string); static String fromUtf8(byte[] bytes);  }### Answer:
@Test public void testToUtf8() throws UnsupportedEncodingException { String multiByteCharString = "\u007A\u6C34\uD834\uDD1E"; byte[] utf8 = TextUtil.toUtf8(multiByteCharString); Assert.assertArrayEquals(multiByteCharString.getBytes("UTF-8"), utf8); }