@Test public void testGetAndSetVarious() throws Exception { // tests reallocation of buffer automatically. WrappedByteBuffer buf = WrappedByteBuffer.allocate(2); buf.put((byte) 1); buf.putShort((short) 2); buf.putInt(3); buf.putLong((long) 4); String test = "this"; buf.putString(test, Charset.defaultCharset()); buf.put((byte) 0); buf.putPrefixedString(1, "abcde", Charset.defaultCharset()); buf.flip(); assertEquals((byte) 1, buf.get()); assertEquals((short) 2, buf.getShort()); assertEquals(3, buf.getInt()); assertEquals((long) 4, buf.getLong()); assertEquals(test, buf.getString(Charset.defaultCharset())); assertEquals("abcde", buf.getPrefixedString(1, Charset.defaultCharset())); }
@Test public void testGetAndSetStringsInASCII() throws Exception { // tests reallocation of buffer automatically. WrappedByteBuffer buf = WrappedByteBuffer.allocate(2); String test = "this"; String test1 = "is"; String test2 = "a"; String test3 = "story"; Charset cs = Charset.forName("ASCII"); buf.putString(test, cs); buf.put((byte) 0); buf.putPrefixedString(2, "abcde", cs); buf.putPrefixedString(2, test1, cs); buf.putPrefixedString(2, test2, cs); buf.putPrefixedString(2, test3, cs); buf.flip(); assertEquals(test, buf.getString(cs)); assertEquals("abcde", buf.getPrefixedString(2, cs)); assertEquals(test1, buf.getPrefixedString(2, cs)); assertEquals(test2, buf.getPrefixedString(2, cs)); assertEquals(test3, buf.getPrefixedString(2, cs)); }