Example usage for java.nio DoubleBuffer rewind

List of usage examples for java.nio DoubleBuffer rewind

Introduction

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

Prototype

public final Buffer rewind() 

Source Link

Document

Rewinds this buffer.

Usage

From source file:Main.java

public static void main(String[] args) {
    DoubleBuffer bb = DoubleBuffer.wrap(new double[] { 98765, 98765 });

    bb.rewind();

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

From source file:Main.java

public static void main(String[] args) {
    DoubleBuffer bb = DoubleBuffer.wrap(new double[] { 98765, 98765 }, 0, 1);

    bb.rewind();

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

From source file:Main.java

public static void main(String[] args) {
    DoubleBuffer bb = DoubleBuffer.allocate(BSIZE);
    bb.put(98765);//from w  ww  .  j  av a 2 s  .com
    bb.put(98765);
    bb.put(98765);
    bb.put(98765);
    bb.put(98765);

    bb.rewind();

    double[] doubleArray = new double[BSIZE];

    bb.get(doubleArray, 0, 2);

    System.out.println(Arrays.toString(doubleArray));

}

From source file:Main.java

public static DoubleBuffer createDoubleBuffer(DoubleBuffer buf, final int size) {
    if (buf != null && buf.limit() == size) {
        buf.rewind();
        return buf;
    }//from  ww w  . ja  v  a 2  s.c om

    buf = createDoubleBuffer(size);
    return buf;
}

From source file:Main.java

/**
 * Creates a double array from the provided {@link DoubleBuffer}.
 * // w  ww . ja  v  a2 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;
}

From source file:Main.java

public static DoubleBuffer clone(final DoubleBuffer buf) {
    if (buf == null) {
        return null;
    }//from  ww  w . j a  v a 2s .  c om
    buf.rewind();

    final DoubleBuffer copy;
    if (buf.isDirect()) {
        copy = createDoubleBuffer(buf.limit());
    } else {
        copy = createDoubleBufferOnHeap(buf.limit());
    }
    copy.put(buf);

    return copy;
}

From source file:Main.java

public static DoubleBuffer clone(final DoubleBuffer buf) {
    if (buf == null) {
        return null;
    }//from   w  ww.j a va  2  s . c  o  m
    buf.rewind();
    final DoubleBuffer copy;
    if (buf.isDirect()) {
        copy = createDoubleBuffer(buf.limit());
    } else {
        copy = createDoubleBufferOnHeap(buf.limit());
    }
    copy.put(buf);

    return copy;
}