Пример #1
0
 @Test
 public void testGetAndSetVarious() throws Exception {
   // tests reallocation of buffer automatically.
   DynamicByteBuffer buf = DynamicByteBuffer.allocate(2);
   buf.put((byte) 1);
   buf.putShort((short) 2);
   buf.putInt(3);
   buf.putLong(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(4, buf.getLong());
   assertEquals(test, buf.getString(Charset.defaultCharset()));
   assertEquals("abcde", buf.getPrefixedString(1, Charset.defaultCharset()));
 }
Пример #2
0
 @Test
 public void testGetAndSetStringsInASCII() throws Exception {
   // tests reallocation of buffer automatically.
   DynamicByteBuffer buf = DynamicByteBuffer.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));
 }