Example usage for java.nio Buffer remaining

List of usage examples for java.nio Buffer remaining

Introduction

In this page you can find the example usage for java.nio Buffer remaining.

Prototype

public final int remaining() 

Source Link

Document

Returns the number of remaining elements in this buffer, that is limit - position .

Usage

From source file:com.navercorp.pinpoint.common.buffer.FixedBufferTest.java

@Test
public void test_remaining() throws Exception {
    final byte[] bytes = new byte[BytesUtils.INT_BYTE_LENGTH];
    Buffer buffer = new FixedBuffer(bytes);
    Assert.assertEquals(buffer.remaining(), 4);
    Assert.assertTrue(buffer.hasRemaining());

    buffer.putInt(1234);/*  w ww  . j a va  2 s.co  m*/
    Assert.assertEquals(buffer.remaining(), 0);
    Assert.assertFalse(buffer.hasRemaining());

    buffer.setOffset(0);
    buffer.putShort((short) 12);
    Assert.assertEquals(buffer.remaining(), 2);
    Assert.assertTrue(buffer.hasRemaining());

    buffer.putByte((byte) 1);
    Assert.assertEquals(buffer.remaining(), 1);
    Assert.assertTrue(buffer.hasRemaining());
}