TextUtil { public static byte[] getBytes(final Text text) { byte[] bytes = text.getBytes(); if (bytes.length != text.getLength()) { bytes = new byte[text.getLength()]; System.arraycopy(text.getBytes(), 0, bytes, 0, bytes.length); } return bytes; } private  TextUtil(); static byte[] getBytes(final Text text); static ByteBuffer getByteBuffer(final Text text);  }
@Test public void testGetBytes() { final Text text = new Text("Some text"); assertEquals(9, TextUtil.getBytes(text).length); assertEquals(new Text("Some text"), new Text(TextUtil.getBytes(text))); }