InputBuffer implements Closeable { public InputBuffer(BufferType type, int inputSize) throws IOException { final int capacity = inputSize; this.type = type; if (capacity > 0) { switch (type) { case DIRECT_BUFFER: this.byteBuffer = bufferPool.getBuffer(capacity); this.byteBuffer.order(ByteOrder.BIG_ENDIAN); break; case HEAP_BUFFER: this.byteBuffer = ByteBuffer.allocate(capacity); this.byteBuffer.order(ByteOrder.BIG_ENDIAN); break; } byteBuffer.position(0); byteBuffer.limit(0); } } InputBuffer(BufferType type, int inputSize);  InputBuffer(byte[] bytes); BufferType getType(); ByteBuffer getByteBuffer(); int length(); void rewind(int startOffset, int length); int remaining(); int position(); int position(int pos); int capacity(); byte[] array(); @Override void close();  }
@Test public void testInputBuffer() throws IOException { final int size = 100; final InputBuffer input1 = new InputBuffer(BufferType.DIRECT_BUFFER, size); Assert.assertEquals(input1.getType(), BufferType.DIRECT_BUFFER); Assert.assertTrue(input1.position() == 0); Assert.assertTrue(input1.length() == 0); Assert.assertTrue(input1.remaining() == 0); Assert.assertTrue(input1.capacity() == size); final InputBuffer input2 = new InputBuffer(BufferType.HEAP_BUFFER, size); Assert.assertEquals(input2.getType(), BufferType.HEAP_BUFFER); Assert.assertTrue(input2.position() == 0); Assert.assertTrue(input2.length() == 0); Assert.assertTrue(input2.remaining() == 0); Assert.assertTrue(input2.capacity() == size); final InputBuffer input3 = new InputBuffer(new byte[size]); Assert.assertEquals(input3.getType(), BufferType.HEAP_BUFFER); Assert.assertTrue(input3.position() == 0); Assert.assertTrue(input3.length() == 0); Assert.assertTrue(input3.remaining() == 0); Assert.assertEquals(input3.capacity(), size); }