@Test public void testGetBytes() { String longMessage = "This is some text"; Text longMessageText = new Text(longMessage); String smallerMessage = "a"; Text smallerMessageText = new Text(smallerMessage); Text someText = new Text(longMessage); assertEquals(someText, longMessageText); someText.set(smallerMessageText); assertTrue(someText.getLength() != someText.getBytes().length); assertEquals(TextUtil.getBytes(someText).length, smallerMessage.length()); assertEquals((new Text(TextUtil.getBytes(someText))), smallerMessageText); }
public static byte[] getBytes(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; }
TextUtil { public static byte[] getBytes(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; } }
TextUtil { public static byte[] getBytes(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; }  }
TextUtil { public static byte[] getBytes(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; }  static byte[] getBytes(Text text); static ByteBuffer getByteBuffer(Text text); static Text truncate(Text text, int maxLen); static Text truncate(Text row); }
TextUtil { public static byte[] getBytes(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; }  static byte[] getBytes(Text text); static ByteBuffer getByteBuffer(Text text); static Text truncate(Text text, int maxLen); static Text truncate(Text row);  }