Exemplo n.º 1
0
 @Test
 public void testGetAndSetBytes() throws Exception {
   DynamicByteBuffer buf = DynamicByteBuffer.allocate(2);
   buf.put((byte) 1);
   buf.put((byte) 2);
   buf.flip();
   assertEquals((byte) 1, buf.get());
   assertEquals((byte) 2, buf.get());
   buf.flip();
   assertEquals((byte) 1, buf.getAt(0));
   assertEquals((byte) 2, buf.getAt(1));
   buf.flip();
 }
Exemplo n.º 2
0
  @Test
  public void testGetAndSetPut() throws Exception {
    DynamicByteBuffer buf = new DynamicByteBuffer();
    byte b1 = (byte) -128;
    byte b2 = (byte) 127;
    byte b3 = (byte) 128;
    byte b4 = (byte) 12;
    byte b5 = (byte) 13;
    buf.put(b1);
    buf.put(b2);
    buf.put(b3);
    buf.flip();

    assertEquals(b1, buf.get());
    assertEquals(b2, buf.get());
    assertEquals(b3, buf.get());

    buf.putAt(0, b4);
    buf.putAt(1, b5);
    assertEquals(b4, buf.getAt(0));
    assertEquals(b5, buf.getAt(1));
  }