Search in sources :

Example 26 with LongBuffer

use of java.nio.LongBuffer in project jna by java-native-access.

the class PointerBufferTest method testLongBufferGet.

public void testLongBufferGet() {
    final long MAGIC = 0x1234567887654321L;
    Memory m = new Memory(8);
    ByteBuffer buf = m.getByteBuffer(0, m.size()).order(ByteOrder.nativeOrder());
    LongBuffer lb = buf.asLongBuffer();
    m.setLong(0, MAGIC);
    assertEquals("Long not read from memory", MAGIC, lb.get(0));
}
Also used : LongBuffer(java.nio.LongBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 27 with LongBuffer

use of java.nio.LongBuffer in project jna by java-native-access.

the class PointerBufferTest method testLongBufferPut.

public void testLongBufferPut() {
    final long MAGIC = 0x1234567887654321L;
    Memory m = new Memory(8);
    ByteBuffer buf = m.getByteBuffer(0, m.size()).order(ByteOrder.nativeOrder());
    LongBuffer lb = buf.asLongBuffer();
    lb.put(MAGIC).flip();
    assertEquals("Long not written to memory", MAGIC, m.getLong(0));
}
Also used : LongBuffer(java.nio.LongBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 28 with LongBuffer

use of java.nio.LongBuffer in project AndroidAsync by koush.

the class WebSocketImpl method toByteArray.

private static byte[] toByteArray(UUID uuid) {
    byte[] byteArray = new byte[(Long.SIZE / Byte.SIZE) * 2];
    ByteBuffer buffer = ByteBuffer.wrap(byteArray);
    LongBuffer longBuffer = buffer.asLongBuffer();
    longBuffer.put(new long[] { uuid.getMostSignificantBits(), uuid.getLeastSignificantBits() });
    return byteArray;
}
Also used : LongBuffer(java.nio.LongBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 29 with LongBuffer

use of java.nio.LongBuffer in project robovm by robovm.

the class StructTest method testStructWithArrayLongArrayAsBuffer.

@Test
public void testStructWithArrayLongArrayAsBuffer() {
    assertEquals(192, StructWithArray.sizeOf());
    final int D1 = 24;
    StructWithArray s = new StructWithArray();
    LongPtr p = s.longArrayAsPtr();
    LongBuffer b1;
    LongBuffer b2;
    LongBuffer b3;
    for (int i = 0; i < D1; i++) {
        p.next(i).set(i + 1);
    }
    b1 = s.longArrayAsBuffer();
    assertEquals(D1, b1.capacity());
    assertEquals(D1, b1.limit());
    assertEquals(0, b1.position());
    for (int i = 0; i < D1; i++) {
        assertEquals(i + 1, b1.get(i));
    }
    b2 = ByteBuffer.allocateDirect(D1 * 8).order(ByteOrder.nativeOrder()).asLongBuffer();
    for (int i = 0; i < D1; i++) {
        b2.put(i, 2 * (i + 1));
    }
    s.longArrayAsBuffer(b2);
    for (int i = 0; i < D1; i++) {
        assertEquals(2 * (i + 1), p.next(i).get());
    }
    b3 = LongBuffer.allocate(D1);
    assertFalse(b3.isDirect());
    for (int i = 0; i < D1; i++) {
        b3.put(i, 3 * (i + 1));
    }
    s.longArrayAsBuffer(b3);
    for (int i = 0; i < D1; i++) {
        assertEquals(3 * (i + 1), p.next(i).get());
    }
    try {
        s.longArrayAsBuffer(LongBuffer.allocate(D1 / 2));
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
}
Also used : LongBuffer(java.nio.LongBuffer) LongPtr(org.robovm.rt.bro.ptr.LongPtr) Test(org.junit.Test)

Example 30 with LongBuffer

use of java.nio.LongBuffer in project robovm by robovm.

the class MachineSizedSIntPtr method get.

/**
     * Copies {@code count} ints from the memory pointed to by this 
     * {@link MachineSizedSIntPtr} to {@code dst} starting at offset {@code offset}.
     * Does the proper narrowing {@code long} to {@code int} conversion if running on 
     * a 64-bit platform.
     * 
     * @param dst the destination.
     * @param offset the offset within the destination array to start copying to.
     * @param count the number of elements to copy.
     */
public void get(int[] dst, int offset, int count) {
    if (_sizeOf() == 4) {
        asIntBuffer(count).get(dst, offset, count);
    } else {
        Arrays.checkOffsetAndCount(dst.length, offset, count);
        LongBuffer buf = asLongBuffer(count);
        for (int i = 0; i < count; i++) {
            dst[i + offset] = (int) buf.get();
        }
    }
}
Also used : LongBuffer(java.nio.LongBuffer)

Aggregations

LongBuffer (java.nio.LongBuffer)49 ByteBuffer (java.nio.ByteBuffer)16 DoubleBuffer (java.nio.DoubleBuffer)10 FloatBuffer (java.nio.FloatBuffer)10 IntBuffer (java.nio.IntBuffer)10 ShortBuffer (java.nio.ShortBuffer)10 CharBuffer (java.nio.CharBuffer)9 Test (org.junit.Test)7 BufferOverflowException (java.nio.BufferOverflowException)4 BufferUnderflowException (java.nio.BufferUnderflowException)3 Bitmap (android.graphics.Bitmap)2 InvalidMarkException (java.nio.InvalidMarkException)2 ByteSource (org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)2 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2 Buffer (java.nio.Buffer)1 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)1 BytePointer (org.bytedeco.javacpp.BytePointer)1 DoublePointer (org.bytedeco.javacpp.DoublePointer)1