Search in sources :

Example 21 with LongBuffer

use of java.nio.LongBuffer in project android_frameworks_base by AOSPA.

the class GLLogWrapper method toByteBuffer.

private ByteBuffer toByteBuffer(int byteCount, Buffer input) {
    ByteBuffer result = null;
    boolean convertWholeBuffer = (byteCount < 0);
    if (input instanceof ByteBuffer) {
        ByteBuffer input2 = (ByteBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = input2.limit() - position;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        for (int i = 0; i < byteCount; i++) {
            result.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof CharBuffer) {
        CharBuffer input2 = (CharBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 2;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        CharBuffer result2 = result.asCharBuffer();
        for (int i = 0; i < byteCount / 2; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof ShortBuffer) {
        ShortBuffer input2 = (ShortBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 2;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        ShortBuffer result2 = result.asShortBuffer();
        for (int i = 0; i < byteCount / 2; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof IntBuffer) {
        IntBuffer input2 = (IntBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 4;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        IntBuffer result2 = result.asIntBuffer();
        for (int i = 0; i < byteCount / 4; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof FloatBuffer) {
        FloatBuffer input2 = (FloatBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 4;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        FloatBuffer result2 = result.asFloatBuffer();
        for (int i = 0; i < byteCount / 4; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof DoubleBuffer) {
        DoubleBuffer input2 = (DoubleBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 8;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        DoubleBuffer result2 = result.asDoubleBuffer();
        for (int i = 0; i < byteCount / 8; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof LongBuffer) {
        LongBuffer input2 = (LongBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 8;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        LongBuffer result2 = result.asLongBuffer();
        for (int i = 0; i < byteCount / 8; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else {
        throw new RuntimeException("Unimplemented Buffer subclass.");
    }
    result.rewind();
    // The OpenGL API will interpret the result in hardware byte order,
    // so we better do that as well:
    result.order(ByteOrder.nativeOrder());
    return result;
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) LongBuffer(java.nio.LongBuffer) IntBuffer(java.nio.IntBuffer) CharBuffer(java.nio.CharBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 22 with LongBuffer

use of java.nio.LongBuffer in project android_frameworks_base by ResurrectionRemix.

the class GLLogWrapper method toByteBuffer.

private ByteBuffer toByteBuffer(int byteCount, Buffer input) {
    ByteBuffer result = null;
    boolean convertWholeBuffer = (byteCount < 0);
    if (input instanceof ByteBuffer) {
        ByteBuffer input2 = (ByteBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = input2.limit() - position;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        for (int i = 0; i < byteCount; i++) {
            result.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof CharBuffer) {
        CharBuffer input2 = (CharBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 2;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        CharBuffer result2 = result.asCharBuffer();
        for (int i = 0; i < byteCount / 2; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof ShortBuffer) {
        ShortBuffer input2 = (ShortBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 2;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        ShortBuffer result2 = result.asShortBuffer();
        for (int i = 0; i < byteCount / 2; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof IntBuffer) {
        IntBuffer input2 = (IntBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 4;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        IntBuffer result2 = result.asIntBuffer();
        for (int i = 0; i < byteCount / 4; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof FloatBuffer) {
        FloatBuffer input2 = (FloatBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 4;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        FloatBuffer result2 = result.asFloatBuffer();
        for (int i = 0; i < byteCount / 4; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof DoubleBuffer) {
        DoubleBuffer input2 = (DoubleBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 8;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        DoubleBuffer result2 = result.asDoubleBuffer();
        for (int i = 0; i < byteCount / 8; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof LongBuffer) {
        LongBuffer input2 = (LongBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 8;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        LongBuffer result2 = result.asLongBuffer();
        for (int i = 0; i < byteCount / 8; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else {
        throw new RuntimeException("Unimplemented Buffer subclass.");
    }
    result.rewind();
    // The OpenGL API will interpret the result in hardware byte order,
    // so we better do that as well:
    result.order(ByteOrder.nativeOrder());
    return result;
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) LongBuffer(java.nio.LongBuffer) IntBuffer(java.nio.IntBuffer) CharBuffer(java.nio.CharBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 23 with LongBuffer

use of java.nio.LongBuffer in project voltdb by VoltDB.

the class ConcurrentHistogram method fillCountsArrayFromBuffer.

@Override
synchronized void fillCountsArrayFromBuffer(final ByteBuffer buffer, final int length) {
    LongBuffer logbuffer = buffer.asLongBuffer();
    for (int i = 0; i < length; i++) {
        inactiveCounts.lazySet(i, logbuffer.get());
        activeCounts.lazySet(i, 0);
    }
}
Also used : LongBuffer(java.nio.LongBuffer)

Example 24 with LongBuffer

use of java.nio.LongBuffer in project XobotOS by xamarin.

the class GLLogWrapper method toByteBuffer.

private ByteBuffer toByteBuffer(int byteCount, Buffer input) {
    ByteBuffer result = null;
    boolean convertWholeBuffer = (byteCount < 0);
    if (input instanceof ByteBuffer) {
        ByteBuffer input2 = (ByteBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = input2.limit() - position;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        for (int i = 0; i < byteCount; i++) {
            result.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof CharBuffer) {
        CharBuffer input2 = (CharBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 2;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        CharBuffer result2 = result.asCharBuffer();
        for (int i = 0; i < byteCount / 2; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof ShortBuffer) {
        ShortBuffer input2 = (ShortBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 2;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        ShortBuffer result2 = result.asShortBuffer();
        for (int i = 0; i < byteCount / 2; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof IntBuffer) {
        IntBuffer input2 = (IntBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 4;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        IntBuffer result2 = result.asIntBuffer();
        for (int i = 0; i < byteCount / 4; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof FloatBuffer) {
        FloatBuffer input2 = (FloatBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 4;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        FloatBuffer result2 = result.asFloatBuffer();
        for (int i = 0; i < byteCount / 4; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof DoubleBuffer) {
        DoubleBuffer input2 = (DoubleBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 8;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        DoubleBuffer result2 = result.asDoubleBuffer();
        for (int i = 0; i < byteCount / 8; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else if (input instanceof LongBuffer) {
        LongBuffer input2 = (LongBuffer) input;
        int position = input2.position();
        if (convertWholeBuffer) {
            byteCount = (input2.limit() - position) * 8;
        }
        result = ByteBuffer.allocate(byteCount).order(input2.order());
        LongBuffer result2 = result.asLongBuffer();
        for (int i = 0; i < byteCount / 8; i++) {
            result2.put(input2.get());
        }
        input2.position(position);
    } else {
        throw new RuntimeException("Unimplemented Buffer subclass.");
    }
    result.rewind();
    // The OpenGL API will interpret the result in hardware byte order,
    // so we better do that as well:
    result.order(ByteOrder.nativeOrder());
    return result;
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) LongBuffer(java.nio.LongBuffer) IntBuffer(java.nio.IntBuffer) CharBuffer(java.nio.CharBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 25 with LongBuffer

use of java.nio.LongBuffer in project geode by apache.

the class ByteSourceJUnitTest method testGetLong.

@Test
public void testGetLong() {
    ByteBuffer bb = ByteBuffer.allocate(40);
    LongBuffer lb = bb.asLongBuffer();
    lb.put(0x1110223344556677L);
    lb.put(0x2220334455667788L);
    lb.put(0x3330445566778899L);
    lb.put(0x4440556677889900L);
    lb.put(0x55506677889900AAL);
    byte[] bytes = bb.array();
    ByteSource bs = createByteSource(bytes);
    long l = bs.getLong();
    assertEquals(0x1110223344556677L, l);
    assertEquals(8, bs.position());
    l = bs.getLong();
    assertEquals(0x2220334455667788L, l);
    assertEquals(16, bs.position());
    bs.position(4 * 8);
    l = bs.getLong();
    assertEquals(0x55506677889900AAL, l);
    assertEquals(40, bs.position());
    try {
        bs.getLong();
        fail("expected BufferUnderflowException");
    } catch (BufferUnderflowException expected) {
    }
}
Also used : LongBuffer(java.nio.LongBuffer) ByteSource(org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource) ByteBuffer(java.nio.ByteBuffer) BufferUnderflowException(java.nio.BufferUnderflowException) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) UnitTest(org.apache.geode.test.junit.categories.UnitTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

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