Buffer { public ByteBuffer getNioBuffer() { synchronized (recycleLock) { ensureNotRecycled(); return memorySegment.wrap(0, currentSize); } } Buffer(MemorySegment memorySegment, BufferRecycler recycler);  Buffer(MemorySegment memorySegment, BufferRecycler recycler, boolean isBuffer); boolean isBuffer(); void tagAsEvent(); MemorySegment getMemorySegment(); ByteBuffer getNioBuffer(); BufferRecycler getRecycler(); int getSize(); void setSize(int newSize); void recycle(); Buffer retain(); boolean isRecycled(); @Override String toString();  }
@Test public void testgetNioBufferThreadSafe() { final MemorySegment segment = MemorySegmentFactory.allocateUnpooledSegment(1024); final BufferRecycler recycler = Mockito.mock(BufferRecycler.class); Buffer buffer = new Buffer(segment, recycler); ByteBuffer buf1 = buffer.getNioBuffer(); ByteBuffer buf2 = buffer.getNioBuffer(); assertNotNull(buf1); assertNotNull(buf2); assertTrue("Repeated call to getNioBuffer() returns the same nio buffer", buf1 != buf2); }