ByteBuffers { public static String getString(ByteBuffer buffer) { return getString(buffer, StandardCharsets.UTF_8); }  static ByteBuffer asReadOnlyBuffer(ByteBuffer source); static ByteBuffer clone(ByteBuffer buffer); static void copyAndRewindSource(ByteBuffer source,
            ByteBuffer destination); static ByteBuffer decodeFromHex(String hex); static String encodeAsHex(ByteBuffer bytes); static String encodeAsHexString(ByteBuffer buffer); static ByteBuffer expand(ByteBuffer destination, ByteBuffer source); static ByteBuffer expandInt(ByteBuffer destination, int value); static ByteBuffer fromString(String string); static ByteBuffer get(ByteBuffer buffer, int length); static boolean getBoolean(ByteBuffer buffer); static T getEnum(ByteBuffer buffer,
            Class<T> clazz); static ByteBuffer getRemaining(ByteBuffer buffer); static String getString(ByteBuffer buffer); static String getString(ByteBuffer buffer, Charset charset); static ByteBuffer nullByteBuffer(); static void putString(String source, ByteBuffer destination); static ByteBuffer rewind(ByteBuffer buffer); static ByteBuffer slice(ByteBuffer buffer, int length); static ByteBuffer slice(ByteBuffer buffer, int position,
            int length); static byte[] toByteArray(ByteBuffer buffer); static CharBuffer toCharBuffer(ByteBuffer buffer); static CharBuffer toCharBuffer(ByteBuffer buffer, Charset charset);  }
@Test public void testDeserializeStringTrailingWhitespace() { String string = Random.getString().trim(); int numWhiteSpaces = Random.getScaleCount(); string = Strings.padEnd(string, string.length() + numWhiteSpaces, ' '); ByteBuffer bytes = ByteBuffer .wrap(string.getBytes(StandardCharsets.UTF_8)); String string2 = ByteBuffers.getString(bytes, StandardCharsets.UTF_8); Assert.assertEquals(string, string2); }
@Test public void testDeserializeStringLeadingWhitespace() { String string = Random.getString().trim(); int numWhiteSpaces = Random.getScaleCount(); string = Strings.padStart(string, string.length() + numWhiteSpaces, ' '); ByteBuffer bytes = ByteBuffer .wrap(string.getBytes(StandardCharsets.UTF_8)); String string2 = ByteBuffers.getString(bytes, StandardCharsets.UTF_8); Assert.assertEquals(string, string2); }
@Test public void testDeserializeStringLeadingAndTrailingWhitespace() { String string = Random.getString().trim(); int numWhiteSpaces1 = Random.getScaleCount(); int numWhiteSpaces2 = Random.getScaleCount(); string = Strings.padStart(string, string.length() + numWhiteSpaces1, ' '); string = Strings.padEnd(string, string.length() + numWhiteSpaces2, ' '); ByteBuffer bytes = ByteBuffer .wrap(string.getBytes(StandardCharsets.UTF_8)); String string2 = ByteBuffers.getString(bytes, StandardCharsets.UTF_8); Assert.assertEquals(string, string2); }
@Test public void testDeserializeStringNoWhitespace() { String string = Random.getString().trim(); ByteBuffer bytes = ByteBuffer .wrap(string.getBytes(StandardCharsets.UTF_8)); String string2 = ByteBuffers.getString(bytes, StandardCharsets.UTF_8); Assert.assertEquals(string, string2); }