setup IntBuffer - Java java.nio

Java examples for java.nio:IntBuffer

Description

setup IntBuffer

Demo Code

/**/*from   ww w .  j  av a 2s .  c o  m*/
 *
 *  You can modify and use this source freely
 *  only for the development of application related Live2D.
 *
 *  (c) Live2D Inc. All rights reserved.
 */
//package com.java2s;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import java.nio.IntBuffer;

public class Main {
    public static Buffer setupIntBuffer(IntBuffer preBuffer, int[] array) {

        if (preBuffer == null || preBuffer.capacity() < array.length) {
            preBuffer = createIntBuffer(array.length * 2);
        } else {
            preBuffer.clear();
        }

        preBuffer.clear();
        preBuffer.put(array);
        preBuffer.position(0);

        return preBuffer;
    }

    public static IntBuffer createIntBuffer(int count) {
        ByteBuffer data = ByteBuffer.allocateDirect(count * 4);
        data.order(ByteOrder.nativeOrder());
        IntBuffer p1 = data.asIntBuffer();
        return p1;
    }
}

Related Tutorials