use of java.nio.LongBuffer in project robovm by robovm.
the class MachineSizedSIntPtr method set.
/**
* Copies {@code count} ints from {@code src} starting at offset {@code offset}
* to the memory pointed to by this {@link MachineSizedSIntPtr}. Does
* signed {@code int} to {@code long} conversion if running on a 64-bit
* platform.
*
* @param src the source.
* @param offset the offset within the source array to start copying from.
* @param count the number of elements to copy.
*/
public void set(int[] src, int offset, int count) {
if (_sizeOf() == 4) {
asIntBuffer(count).put(src, offset, count);
} else {
Arrays.checkOffsetAndCount(src.length, offset, count);
LongBuffer buf = asLongBuffer(count);
for (int i = 0; i < count; i++) {
buf.put(src[i + offset]);
}
}
}
use of java.nio.LongBuffer in project robovm by robovm.
the class MachineSizedUIntPtr method set.
/**
* Copies {@code count} ints from {@code src} starting at offset {@code offset}
* to the memory pointed to by this {@link MachineSizedUIntPtr}. Does
* unsigned {@code int} to {@code long} conversion if running on a 64-bit
* platform.
*
* @param src the source.
* @param offset the offset within the source array to start copying from.
* @param count the number of elements to copy.
*/
public void set(int[] src, int offset, int count) {
if (_sizeOf() == 4) {
asIntBuffer(count).put(src, offset, count);
} else {
Arrays.checkOffsetAndCount(src.length, offset, count);
LongBuffer buf = asLongBuffer(count);
for (int i = 0; i < count; i++) {
buf.put(((long) src[i + offset]) & 0xffffffffL);
}
}
}
use of java.nio.LongBuffer in project robovm by robovm.
the class ByteBufferTest method testAsLongBuffer.
public void testAsLongBuffer() {
LongBuffer longBuffer;
byte[] bytes = new byte[8];
long value;
// test BIG_ENDIAN long buffer, read
buf.clear();
buf.order(ByteOrder.BIG_ENDIAN);
longBuffer = buf.asLongBuffer();
assertSame(ByteOrder.BIG_ENDIAN, longBuffer.order());
while (longBuffer.remaining() > 0) {
buf.get(bytes);
value = longBuffer.get();
assertEquals(bytes2long(bytes, buf.order()), value);
}
// test LITTLE_ENDIAN long buffer, read
buf.clear();
buf.order(ByteOrder.LITTLE_ENDIAN);
longBuffer = buf.asLongBuffer();
assertSame(ByteOrder.LITTLE_ENDIAN, longBuffer.order());
while (longBuffer.remaining() > 0) {
buf.get(bytes);
value = longBuffer.get();
assertEquals(bytes2long(bytes, buf.order()), value);
}
if (!buf.isReadOnly()) {
// test BIG_ENDIAN long buffer, write
buf.clear();
buf.order(ByteOrder.BIG_ENDIAN);
longBuffer = buf.asLongBuffer();
assertSame(ByteOrder.BIG_ENDIAN, longBuffer.order());
while (longBuffer.remaining() > 0) {
value = (long) longBuffer.remaining();
longBuffer.put(value);
buf.get(bytes);
assertTrue(Arrays.equals(bytes, long2bytes(value, buf.order())));
}
// test LITTLE_ENDIAN long buffer, write
buf.clear();
buf.order(ByteOrder.LITTLE_ENDIAN);
longBuffer = buf.asLongBuffer();
assertSame(ByteOrder.LITTLE_ENDIAN, longBuffer.order());
while (longBuffer.remaining() > 0) {
value = (long) longBuffer.remaining();
longBuffer.put(value);
buf.get(bytes);
assertTrue(Arrays.equals(bytes, long2bytes(value, buf.order())));
}
}
buf.clear();
buf.order(ByteOrder.BIG_ENDIAN);
}
use of java.nio.LongBuffer in project robovm by robovm.
the class LongBufferTest method testCompact.
public void testCompact() {
// case: buffer is full
buf.clear();
buf.mark();
loadTestData1(buf);
LongBuffer ret = buf.compact();
assertSame(ret, buf);
assertEquals(buf.position(), buf.capacity());
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, 0, buf.capacity());
try {
buf.reset();
//$NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
// case: buffer is empty
buf.position(0);
buf.limit(0);
buf.mark();
ret = buf.compact();
assertSame(ret, buf);
assertEquals(buf.position(), 0);
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, 0, buf.capacity());
try {
buf.reset();
//$NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
// case: normal
assertTrue(buf.capacity() > 5);
buf.position(1);
buf.limit(5);
buf.mark();
ret = buf.compact();
assertSame(ret, buf);
assertEquals(buf.position(), 4);
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, 1, 4);
try {
buf.reset();
//$NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
}
use of java.nio.LongBuffer in project robovm by robovm.
the class LongBufferTest method testGetlongArray.
/*
* Class under test for java.nio.LongBuffer get(long[])
*/
public void testGetlongArray() {
long[] array = new long[1];
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(buf.position(), i);
LongBuffer ret = buf.get(array);
assertEquals(array[0], buf.get(i));
assertSame(ret, buf);
}
try {
buf.get(array);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (BufferUnderflowException e) {
// expected
}
try {
buf.position(buf.limit());
buf.get((long[]) null);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (NullPointerException e) {
// expected
}
}
Aggregations