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));
}
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));
}
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;
}
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) {
}
}
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();
}
}
}
Aggregations