### Question:
ByteBufferIOEngine implements IOEngine { public ByteBufferIOEngine(long capacity, boolean direct) throws IOException { bufferArray = new ByteBufferArray(capacity, direct); } ByteBufferIOEngine(long capacity, boolean direct); @Override boolean isPersistent(); @Override void read(ByteBuffer dstBuffer, long offset); @Override void write(ByteBuffer srcBuffer, long offset); @Override void sync(); @Override void shutdown();  }### Answer:
@Test public void testByteBufferIOEngine() throws Exception { int capacity = 32 * 1024 * 1024; int testNum = 100; int maxBlockSize = 64 * 1024; ByteBufferIOEngine ioEngine = new ByteBufferIOEngine(capacity, false); int testOffsetAtStartNum = testNum / 10; int testOffsetAtEndNum = testNum / 10; for (int i = 0; i < testNum; i++) { byte val = (byte) (Math.random() * 255); int blockSize = (int) (Math.random() * maxBlockSize); byte[] byteArray = new byte[blockSize]; for (int j = 0; j < byteArray.length; ++j) { byteArray[j] = val; } ByteBuffer srcBuffer = ByteBuffer.wrap(byteArray); int offset = 0; if (testOffsetAtStartNum > 0) { testOffsetAtStartNum--; offset = 0; } else if (testOffsetAtEndNum > 0) { testOffsetAtEndNum--; offset = capacity - blockSize; } else { offset = (int) (Math.random() * (capacity - maxBlockSize)); } ioEngine.write(srcBuffer, offset); ByteBuffer dstBuffer = ByteBuffer.allocate(blockSize); ioEngine.read(dstBuffer, offset); byte[] byteArray2 = dstBuffer.array(); for (int j = 0; j < byteArray.length; ++j) { assertTrue(byteArray[j] == byteArray2[j]); } } assert testOffsetAtStartNum == 0; assert testOffsetAtEndNum == 0; }