Android FloatBuffer Create createFloatBuffer(int capacity)

Here you can find the source of createFloatBuffer(int capacity)

Description

Creates a FloatBuffer with the specified capacity.

Parameter

Parameter Description
capacity buffer capacity

Return

FloatBuffer with the specified capacity

Declaration

public static FloatBuffer createFloatBuffer(int capacity) 

Method Source Code

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

public class Main {
    /**//from  w ww  .ja va  2  s.co m
     * Creates a FloatBuffer with the specified capacity.
     * 
     * @param capacity
     *            buffer capacity
     * @return FloatBuffer with the specified capacity
     */
    public static FloatBuffer createFloatBuffer(int capacity) {
        return createByteBuffer(capacity * 4).asFloatBuffer();
    }

    /**
     * Creates a FloatBuffer from the specified float array.
     * 
     * @param data
     *            float array to convert to a FloatBuffer
     * @return FloatBuffer with the same content as data
     */
    public static FloatBuffer createFloatBuffer(float[] data) {
        FloatBuffer b = createFloatBuffer(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. newFloatBuffer(int numFloats)
  2. newFloatBuffer(int numFloats)
  3. createFloatBuffer(float[] data)
  4. createFloatBuffer(float[] floatData)
  5. createFloatBuffer(float[] floatData)
  6. createFloatBuffer(int floatCount)
  7. createFloatBuffer(int nElements, int stride)
  8. createFloatBuffer(int nElements, int stride)
  9. createFloatBuffer(int size)