Android IntBuffer Create createIntBuffer(int[] data)

Here you can find the source of createIntBuffer(int[] data)

Description

Creates a IntBuffer from the specified int array.

Parameter

Parameter Description
data int array to convert to a IntBuffer

Return

IntBuffer with the same content as data

Declaration

public static IntBuffer createIntBuffer(int[] data) 

Method Source Code

//package com.java2s;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import java.nio.IntBuffer;

public class Main {
    /**//from  www.  j a  v  a 2 s  . co m
     * Creates a IntBuffer with the specified capacity.
     * 
     * @param capacity
     *            buffer capacity
     * @return IntBuffer with the specified capacity
     */
    public static IntBuffer createIntBuffer(int capacity) {
        return createByteBuffer(capacity * 4).asIntBuffer();
    }

    /**
     * Creates a IntBuffer from the specified int array.
     * 
     * @param data
     *            int array to convert to a IntBuffer
     * @return IntBuffer with the same content as data
     */
    public static IntBuffer createIntBuffer(int[] data) {
        IntBuffer b = createIntBuffer(data.length);
        b.put(data);
        b.rewind();
        return b;
    }

    /**
     * Creates a ByteBuffer with the specified capacity.
     * 
     * @param capacity
     *            buffer capacity
     * @return ByteBuffer with the specified capacity
     */
    public static ByteBuffer createByteBuffer(int capacity) {
        ByteBuffer b = ByteBuffer.allocateDirect(capacity);
        b.order(ByteOrder.nativeOrder());
        return b;
    }

    /**
     * Creates a ByteBuffer from the specified byte array.
     * 
     * @param data
     *            byte array to convert to a ByteBuffer
     * @return ByteBuffer with the same content as data
     */
    public static ByteBuffer createByteBuffer(byte[] data) {
        ByteBuffer b = createByteBuffer(data.length);
        b.put(data);
        b.rewind();
        return b;
    }
}

Related

  1. newIntBuffer(int numInts)
  2. newIntBuffer(int numInts)
  3. createIntBuffer(int capacity)
  4. createIntBuffer(int count)
  5. createIntBuffer(int size)
  6. getIntegerBuffer(int[] list)
  7. makeIntBuffer(int size)
  8. makeIntBuffer(int[] arr)
  9. newIntBuffer(int numInts)