Example usage for java.nio DoubleBuffer array

List of usage examples for java.nio DoubleBuffer array

Introduction

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

Prototype

public final double[] array() 

Source Link

Document

Returns the double array which this buffer is based on, if there is one.

Usage

From source file:Main.java

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

    bb.put(new double[] { 98765, 12345 }, 0, 1);

    System.out.println(Arrays.toString(bb.array()));

}

From source file:Main.java

/**
 * Creates a double array from the provided {@link DoubleBuffer}.
 * // w  w w .  jav a2  s.  co m
 * @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;
}