Search in sources :

Example 6 with DirectByteBuffer

use of java.nio.DirectByteBuffer in project j2objc by google.

the class DirectFloatBufferTest method testJNIAccessByAddress.

// http://b/28964300
public void testJNIAccessByAddress() throws Exception {
    DirectByteBuffer directByteBuffer = (DirectByteBuffer) ByteBuffer.allocateDirect(10);
    directByteBuffer.put((byte) 'a');
    FloatBuffer floatBuffer = directByteBuffer.asFloatBuffer();
    long byteBufferBasePointer = NIOAccess.getBasePointer(directByteBuffer);
    long floatBufferBasePointer = NIOAccess.getBasePointer(floatBuffer);
    assertEquals(byteBufferBasePointer, floatBufferBasePointer);
    // Check if the NIOAccess method adds up the current position value.
    floatBuffer.put((float) 1);
    assertEquals(floatBufferBasePointer + Float.BYTES, NIOAccess.getBasePointer(floatBuffer));
}
Also used : FloatBuffer(java.nio.FloatBuffer) DirectByteBuffer(java.nio.DirectByteBuffer)

Example 7 with DirectByteBuffer

use of java.nio.DirectByteBuffer in project j2objc by google.

the class DirectLongBufferTest method testJNIAccessByAddress.

// http://b/28964300
public void testJNIAccessByAddress() throws Exception {
    DirectByteBuffer directByteBuffer = (DirectByteBuffer) ByteBuffer.allocateDirect(10);
    directByteBuffer.put((byte) 'a');
    LongBuffer longBuffer = directByteBuffer.asLongBuffer();
    long byteBufferBasePointer = NIOAccess.getBasePointer(directByteBuffer);
    long longBufferBasePointer = NIOAccess.getBasePointer(longBuffer);
    assertEquals(byteBufferBasePointer, longBufferBasePointer);
    // Check if the NIOAccess method adds up the current position value.
    longBuffer.put(1L);
    assertEquals(longBufferBasePointer + Long.BYTES, NIOAccess.getBasePointer(longBuffer));
}
Also used : LongBuffer(java.nio.LongBuffer) DirectByteBuffer(java.nio.DirectByteBuffer)

Aggregations

DirectByteBuffer (java.nio.DirectByteBuffer)7 FileDescriptor (java.io.FileDescriptor)1 IOException (java.io.IOException)1 CharBuffer (java.nio.CharBuffer)1 DoubleBuffer (java.nio.DoubleBuffer)1 FloatBuffer (java.nio.FloatBuffer)1 IntBuffer (java.nio.IntBuffer)1 LongBuffer (java.nio.LongBuffer)1 ShortBuffer (java.nio.ShortBuffer)1 NonReadableChannelException (java.nio.channels.NonReadableChannelException)1 NonWritableChannelException (java.nio.channels.NonWritableChannelException)1