Search in sources :

Example 36 with LongBuffer

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);
}
Also used : LongBuffer(java.nio.LongBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 37 with LongBuffer

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();
        }
    }
}
Also used : LongBuffer(java.nio.LongBuffer)

Example 38 with LongBuffer

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);
    }
}
Also used : LongBuffer(java.nio.LongBuffer) InvalidMarkException(java.nio.InvalidMarkException)

Example 39 with LongBuffer

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());
}
Also used : LongBuffer(java.nio.LongBuffer)

Example 40 with LongBuffer

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
    }
}
Also used : LongBuffer(java.nio.LongBuffer) BufferOverflowException(java.nio.BufferOverflowException)

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