Example usage for java.nio FloatBuffer hasArray

List of usage examples for java.nio FloatBuffer hasArray

Introduction

In this page you can find the example usage for java.nio FloatBuffer hasArray.

Prototype

public final boolean hasArray() 

Source Link

Document

Indicates whether this buffer is based on a float array and is read/write.

Usage

From source file:Main.java

public static void main(String[] args) {
    FloatBuffer floatBuffer = FloatBuffer.allocate(10);

    floatBuffer.put(1, 1.23F);/*from  w  ww.j a v  a  2 s  .c o m*/

    System.out.println(floatBuffer.hasArray());

}

From source file:Main.java

/**
 * Creates a float array from the provided {@link FloatBuffer}.
 * //from w  w w .  ja v  a  2s  . c  om
 * @param buffer {@link FloatBuffer} the data source.
 * @return float array containing the data of the buffer.
 */
public static float[] getFloatArrayFromBuffer(FloatBuffer buffer) {
    float[] array = null;
    if (buffer.hasArray()) {
        array = buffer.array();
    } else {
        buffer.rewind();
        array = new float[buffer.capacity()];
        buffer.get(array);
    }
    return array;
}