@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); if (blockSize == 0) { blockSize = 1; } 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; }
public ByteBufferIOEngine(long capacity, boolean direct) throws IOException { this.capacity = capacity; this.direct = direct; bufferArray = new ByteBufferArray(capacity, direct); }
ByteBufferIOEngine implements IOEngine { public ByteBufferIOEngine(long capacity, boolean direct) throws IOException { this.capacity = capacity; this.direct = direct; bufferArray = new ByteBufferArray(capacity, direct); } }
ByteBufferIOEngine implements IOEngine { public ByteBufferIOEngine(long capacity, boolean direct) throws IOException { this.capacity = capacity; this.direct = direct; bufferArray = new ByteBufferArray(capacity, direct); } ByteBufferIOEngine(long capacity, boolean direct); }
ByteBufferIOEngine implements IOEngine { public ByteBufferIOEngine(long capacity, boolean direct) throws IOException { this.capacity = capacity; this.direct = direct; bufferArray = new ByteBufferArray(capacity, direct); } ByteBufferIOEngine(long capacity, boolean direct); @Override String toString(); @Override boolean isPersistent(); @Override int read(ByteBuffer dstBuffer, long offset); @Override void write(ByteBuffer srcBuffer, long offset); @Override void sync(); @Override void shutdown(); }
ByteBufferIOEngine implements IOEngine { public ByteBufferIOEngine(long capacity, boolean direct) throws IOException { this.capacity = capacity; this.direct = direct; bufferArray = new ByteBufferArray(capacity, direct); } ByteBufferIOEngine(long capacity, boolean direct); @Override String toString(); @Override boolean isPersistent(); @Override int read(ByteBuffer dstBuffer, long offset); @Override void write(ByteBuffer srcBuffer, long offset); @Override void sync(); @Override void shutdown();  }