public class UnsafeMemoryInputOutputTest extends KryoTestCase {
public void testByteBufferOutputWithPreallocatedMemory () {
long bufAddress = UnsafeUtil.unsafe().allocateMemory(4096);
try {
ByteBufferOutput outputBuffer = new ByteBufferOutput(bufAddress, 4096);
outputBuffer.writeInt(10);
ByteBufferInput inputBuffer = new ByteBufferInput(outputBuffer.getByteBuffer());
inputBuffer.readInt();
inputBuffer.release();
outputBuffer.release();
outputBuffer = new UnsafeMemoryOutput(bufAddress, 4096);
outputBuffer.writeInt(10);
inputBuffer = new UnsafeMemoryInput(outputBuffer.getByteBuffer());
inputBuffer.readInt();
inputBuffer.release();
outputBuffer.release();
} catch (Throwable t) {
System.err.println("Streams with preallocated direct memory are not supported on this JVM");
t.printStackTrace();
} finally {
UnsafeUtil.unsafe().freeMemory(bufAddress);