Android IntBuffer Create setupIntBuffer(IntBuffer preBuffer, int[] array)

Here you can find the source of setupIntBuffer(IntBuffer preBuffer, int[] array)

Description

setup Int Buffer

License

Open Source License

Declaration

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

Method Source Code

//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 {/* w  w  w  . ja v  a 2 s  . c  om*/
            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

  1. makeIntBuffer(int size)
  2. makeIntBuffer(int[] arr)
  3. newIntBuffer(int numInts)
  4. newIntBuffer(int numInts)
  5. newIntBuffer(int paramInt)
  6. toIntBuffer(int[] array)
  7. createDirectIntBuffer(final int capacity)
  8. createDirectIntBuffer(final int capacity, final IntBuffer previous)
  9. buildIntBuffer(int[] buffer)