use of java.nio.LongBuffer in project libgdx by libgdx.
the class BufferUtils method copy.
/** Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. The {@link Buffer} instance's
* {@link Buffer#position()} is used to define the offset into the Buffer itself. The position and limit will stay the same.
* <b>The Buffer must be a direct Buffer with native byte order. No error checking is performed</b>.
*
* @param src the source array.
* @param srcOffset the offset into the source array.
* @param numElements the number of elements to copy.
* @param dst the destination Buffer, its position is used as an offset. */
public static void copy(long[] src, int srcOffset, int numElements, Buffer dst) {
LongBuffer buffer = null;
if (dst instanceof ByteBuffer)
buffer = ((ByteBuffer) dst).asLongBuffer();
else if (dst instanceof LongBuffer)
buffer = (LongBuffer) dst;
if (buffer == null)
throw new GdxRuntimeException("dst must be a ByteBuffer or LongBuffer");
int oldPosition = buffer.position();
buffer.put(src, srcOffset, numElements);
buffer.position(oldPosition);
}
use of java.nio.LongBuffer in project robovm by robovm.
the class MachineSizedUIntPtr method get.
/**
* Copies {@code count} ints from the memory pointed to by this
* {@link MachineSizedUIntPtr} 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();
}
}
}
use of java.nio.LongBuffer in project robovm by robovm.
the class LongBufferTest method testSlice.
public void testSlice() {
assertTrue(buf.capacity() > 5);
buf.position(1);
buf.limit(buf.capacity() - 1);
LongBuffer slice = buf.slice();
assertEquals(buf.isReadOnly(), slice.isReadOnly());
assertEquals(buf.isDirect(), slice.isDirect());
assertEquals(buf.order(), slice.order());
assertEquals(slice.position(), 0);
assertEquals(slice.limit(), buf.remaining());
assertEquals(slice.capacity(), buf.remaining());
try {
slice.reset();
//$NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
// slice share the same content with buf
if (!slice.isReadOnly()) {
loadTestData1(slice);
assertContentLikeTestData1(buf, 1, 0, slice.capacity());
buf.put(2, 500);
assertEquals(slice.get(1), 500);
}
}
use of java.nio.LongBuffer in project robovm by robovm.
the class LongBufferTest method testHashCode.
public void testHashCode() {
buf.clear();
LongBuffer readonly = buf.asReadOnlyBuffer();
LongBuffer duplicate = buf.duplicate();
assertTrue(buf.hashCode() == readonly.hashCode());
assertTrue(buf.capacity() > 5);
duplicate.position(buf.capacity() / 2);
assertTrue(buf.hashCode() != duplicate.hashCode());
}
use of java.nio.LongBuffer in project robovm by robovm.
the class LongBufferTest method testPutlongArray.
/*
* Class under test for java.nio.LongBuffer put(long[])
*/
public void testPutlongArray() {
long[] array = new long[1];
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(buf.position(), i);
array[0] = (long) i;
LongBuffer ret = buf.put(array);
assertEquals(buf.get(i), (long) i);
assertSame(ret, buf);
}
try {
buf.put(array);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (BufferOverflowException e) {
// expected
}
try {
buf.position(buf.limit());
buf.put((long[]) null);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (NullPointerException e) {
// expected
}
}
Aggregations