Example usage for java.nio DoubleBuffer hasArray

List of usage examples for java.nio DoubleBuffer hasArray

Introduction

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

Prototype

public final boolean hasArray() 

Source Link

Document

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

Usage

From source file:Main.java

public static void main(String[] args) {
    DoubleBuffer bb = DoubleBuffer.allocate(BSIZE);

    bb.put(98765);/* w  ww.ja  va2  s . c  o m*/
    System.out.println(bb.hasArray());

}

From source file:Main.java

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