OutputBuffer { public OutputBuffer(BufferType type, int outputBufferCapacity) { this.type = type; if (outputBufferCapacity > 0) { switch (type) { case DIRECT_BUFFER: this.byteBuffer = ByteBuffer.allocateDirect(outputBufferCapacity); this.byteBuffer.order(ByteOrder.BIG_ENDIAN); break; case HEAP_BUFFER: this.byteBuffer = ByteBuffer.allocate(outputBufferCapacity); this.byteBuffer.order(ByteOrder.BIG_ENDIAN); break; } } } OutputBuffer(BufferType type, int outputBufferCapacity);  OutputBuffer(byte[] bytes); BufferType getType(); ByteBuffer getByteBuffer(); int length(); void rewind(); int limit();  }
@Test public void testOutputBuffer() { final int size = 100; final OutputBuffer output1 = new OutputBuffer(BufferType.DIRECT_BUFFER, size); Assert.assertEquals(output1.getType(), BufferType.DIRECT_BUFFER); Assert.assertTrue(output1.length() == 0); Assert.assertEquals(output1.limit(), size); final OutputBuffer output2 = new OutputBuffer(BufferType.HEAP_BUFFER, size); Assert.assertEquals(output2.getType(), BufferType.HEAP_BUFFER); Assert.assertTrue(output2.length() == 0); Assert.assertEquals(output2.limit(), size); final OutputBuffer output3 = new OutputBuffer(new byte[size]); Assert.assertEquals(output3.getType(), BufferType.HEAP_BUFFER); Assert.assertTrue(output3.length() == 0); Assert.assertEquals(output3.limit(), size); }