Example usage for java.nio ByteBuffer asFloatBuffer

List of usage examples for java.nio ByteBuffer asFloatBuffer

Introduction

In this page you can find the example usage for java.nio ByteBuffer asFloatBuffer.

Prototype

public abstract FloatBuffer asFloatBuffer();

Source Link

Document

Returns a float buffer which is based on the remaining content of this byte buffer.

Usage

From source file:Main.java

public static FloatBuffer newFloatBuffer(int numElements) {
    ByteBuffer bb = newByteBuffer(numElements * SIZEOF_FLOAT);
    return bb.asFloatBuffer();
}

From source file:Main.java

/**
 * @param size number of floats the buffer should hold
 * @return the newly allocated float buffer
 *///from   w w  w.  j  a va  2 s .  c  o m
public static FloatBuffer createFloatBuffer(int size) {
    ByteBuffer bb = ByteBuffer.allocateDirect(4 * size);
    bb.order(ByteOrder.nativeOrder());
    return bb.asFloatBuffer();
}

From source file:Main.java

public static ByteBuffer copyFloatBufferAsByteBuffer(FloatBuffer buf) {
    ByteBuffer dest = newByteBuffer(buf.remaining() * SIZEOF_FLOAT);
    buf.mark();// w w  w.  j a v a 2 s  .  c o m
    dest.asFloatBuffer().put(buf);
    buf.reset();
    dest.rewind();
    return dest;
}

From source file:Main.java

public static FloatBuffer allocateFloatBuffer(int capacity) {
    ByteBuffer vbb = ByteBuffer.allocateDirect(capacity);
    vbb.order(ByteOrder.nativeOrder());
    return vbb.asFloatBuffer();
}

From source file:Main.java

public static FloatBuffer float2Buffer(float[] a) {
    FloatBuffer floatBuffer;//from   w  w w  .j av a 2 s  . c  om
    ByteBuffer bb = ByteBuffer.allocateDirect(a.length * 4);
    bb.order(ByteOrder.nativeOrder());
    floatBuffer = bb.asFloatBuffer();
    floatBuffer.put(a);
    floatBuffer.position(0);
    return floatBuffer;
}

From source file:Main.java

public static FloatBuffer makeFloatBufferFromArray(float[] arr) {
    ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4);
    bb.order(ByteOrder.nativeOrder());
    FloatBuffer fb = bb.asFloatBuffer();
    fb.put(arr);/*from  w  w  w  . j av a 2s.  co  m*/
    fb.position(0);
    return fb;
}

From source file:Main.java

public static FloatBuffer createFloatBuffer(int floatCount) {
    ByteBuffer data = ByteBuffer.allocateDirect(floatCount * 4);
    data.order(ByteOrder.nativeOrder());
    FloatBuffer p1 = data.asFloatBuffer();
    return p1;//from   w w w  . ja v a 2  s  .  c  om
}

From source file:Main.java

public static FloatBuffer makeFloatBuffer(int i_len) {
    ByteBuffer bb = ByteBuffer.allocateDirect(i_len * 4);
    bb.order(ByteOrder.nativeOrder());
    FloatBuffer fb = bb.asFloatBuffer();
    fb.position(0);/* w w w  .ja  v a2  s  .  c om*/
    return fb;
}

From source file:Main.java

public static FloatBuffer allocateFloatBuffer(int capacity) {
    final ByteBuffer vbb = ByteBuffer.allocateDirect(capacity);
    vbb.order(ByteOrder.nativeOrder());
    return vbb.asFloatBuffer();
}

From source file:Main.java

/**
 * Make a direct NIO FloatBuffer from an array of floats
 * @param arr The array/* ww  w  .  j  a v a 2  s  . c om*/
 * @return The newly created FloatBuffer
 */
public static FloatBuffer makeFloatBuffer(float[] arr) {
    ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4);
    bb.order(ByteOrder.nativeOrder());
    FloatBuffer fb = bb.asFloatBuffer();
    fb.put(arr);
    fb.position(0);
    return fb;
}