示例#1
0
  // Long tests
  @Test
  public void testGetAndSetLong() throws Exception {
    DynamicByteBuffer buf = new DynamicByteBuffer();
    long b1 = -9223372036854775808L;
    long b2 = 9223372036854775807L;
    long b3 = 32768;
    long b4 = 543210987654321L;
    long b5 = 123456789012345L;
    buf.putLong(b1);
    buf.putLong(b2);
    buf.putLong(b3);
    buf.flip();

    assertEquals(b1, buf.getLong());
    assertEquals(b2, buf.getLong());

    buf.rewind();
    buf.putLongAt(0, b4);
    buf.putLongAt(8, b5);
    assertEquals(b4, buf.getLongAt(0));
    assertEquals(b5, buf.getLongAt(8));
  }
示例#2
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()));
 }
示例#3
0
 @Test(expected = BufferOverflowException.class)
 public void testGetAndSetPutLongException() {
   DynamicByteBuffer buf = DynamicByteBuffer.allocate(0);
   buf.setAutoExpand(false);
   buf.putLong(121L);
 }