Search in sources :

Example 31 with LongBuffer

use of java.nio.LongBuffer in project HdrHistogram by HdrHistogram.

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 32 with LongBuffer

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

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 33 with LongBuffer

use of java.nio.LongBuffer in project platform_frameworks_base by android.

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 34 with LongBuffer

use of java.nio.LongBuffer in project robovm by robovm.

the class GlobalValueTest method testStructByRef.

@Test
public void testStructByRef() throws Exception {
    LongBuffer memoryAsLongBuffer = memory.order(ByteOrder.nativeOrder()).asLongBuffer();
    assertEquals(0, memoryAsLongBuffer.get(0));
    assertNull(structByRefGetter());
    Point p = new Point();
    structByRefSetter(p);
    assertEquals(p.getHandle(), memoryAsLongBuffer.get(0));
}
Also used : LongBuffer(java.nio.LongBuffer) Test(org.junit.Test)

Example 35 with LongBuffer

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

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)

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