private static ByteBuffer proxy( long buffer, int bufferLength ) throws IOException { ByteBuffer buf = proxyCache.get(); if ( buf != null ) { UnsafeUtil.initDirectByteBuffer( buf, buffer, bufferLength ); return buf; } return createAndGetNewBuffer( buffer, bufferLength ); }
/** * Create a new DirectByteBuffer that wraps the given address and has the given capacity. * <p> * The ByteBuffer does NOT create a Cleaner, or otherwise register the pointer for freeing. */ public static ByteBuffer newDirectByteBuffer( long addr, int cap ) throws Exception { if ( directByteBufferCtor == null ) { // Simulate the JNI NewDirectByteBuffer(void*, long) invocation. Object dbb = unsafe.allocateInstance( directByteBufferClass ); initDirectByteBuffer( dbb, addr, cap ); return (ByteBuffer) dbb; } // Reflection based fallback code. return (ByteBuffer) directByteBufferCtor.newInstance( addr, cap ); }
initDirectByteBuffer( a, address2, sizeInBytes2 ); assertThat( a.hasArray(), is( false ) ); assertThat( a.isDirect(), is( true ) );
private static ByteBuffer proxy( long buffer, int bufferLength ) throws IOException { ByteBuffer buf = proxyCache.get(); if ( buf != null ) { UnsafeUtil.initDirectByteBuffer( buf, buffer, bufferLength ); return buf; } return createAndGetNewBuffer( buffer, bufferLength ); }
/** * Create a new DirectByteBuffer that wraps the given address and has the given capacity. * <p> * The ByteBuffer does NOT create a Cleaner, or otherwise register the pointer for freeing. */ public static ByteBuffer newDirectByteBuffer( long addr, int cap ) throws Exception { if ( directByteBufferCtor == null ) { // Simulate the JNI NewDirectByteBuffer(void*, long) invocation. Object dbb = unsafe.allocateInstance( directByteBufferClass ); initDirectByteBuffer( dbb, addr, cap ); return (ByteBuffer) dbb; } // Reflection based fallback code. return (ByteBuffer) directByteBufferCtor.newInstance( addr, cap ); }