Example usage for java.nio FloatBuffer position

List of usage examples for java.nio FloatBuffer position

Introduction

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

Prototype

public final Buffer position(int newPosition) 

Source Link

Document

Sets the position of this buffer.

Usage

From source file:Main.java

public static FloatBuffer replaceFloats(FloatBuffer dest, float... src) {
    dest.clear();/*from  w  w w . j  av a 2s  .c  om*/
    dest.put(src);
    dest.position(0);
    return dest;
}

From source file:Main.java

/**
 * Make a FloatBuffer from an array of floats
 * //from   w  w w .  j  a v  a2  s.  c  o  m
 * @param f
 *            The array
 * @return the FloatBuffer
 */
public static FloatBuffer makeFloatBuffer(float[] f) {
    ByteBuffer bytBuffer = ByteBuffer.allocateDirect(f.length * 4);
    bytBuffer.order(ByteOrder.nativeOrder());

    FloatBuffer floatBuffer = bytBuffer.asFloatBuffer();
    floatBuffer.put(f);
    floatBuffer.position(0);

    return floatBuffer;
}

From source file:Main.java

/**
 * Copies floats from one position in the buffer to another.
 * //w  w w .  ja v  a2 s. c o m
 * @param buf
 *            the buffer to copy from/to
 * @param fromPos
 *            the starting point to copy from
 * @param toPos
 *            the starting point to copy to
 * @param length
 *            the number of floats to copy
 */
public static void copyInternal(FloatBuffer buf, int fromPos, int toPos, int length) {
    float[] data = new float[length];
    buf.position(fromPos);
    buf.get(data);
    buf.position(toPos);
    buf.put(data);
}

From source file:Main.java

public static FloatBuffer makeFloatBuffer3(float $a, float $b, float $c) {
    ByteBuffer b = ByteBuffer.allocateDirect(3 * BYTES_PER_FLOAT);
    b.order(ByteOrder.nativeOrder());
    FloatBuffer buffer = b.asFloatBuffer();
    buffer.put($a);// ww  w . jav a 2s.c om
    buffer.put($b);
    buffer.put($c);
    buffer.position(0);
    return buffer;
}

From source file:Main.java

public static FloatBuffer makeFloatBuffer(float[] array) {
    final int floatSize = Float.SIZE / 8;
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(array.length * floatSize);
    byteBuffer.order(ByteOrder.nativeOrder());
    FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
    floatBuffer.put(array);/*w w  w  . j  a  va2 s  .co m*/
    floatBuffer.position(0);
    return floatBuffer;
}

From source file:Main.java

public static FloatBuffer createFloatBuffer(float... floats) {
    FloatBuffer fb = createFloatBuffer(floats.length);
    fb.put(floats);/*from   w  w w . j a  va 2  s .  c  o  m*/
    fb.position(0);
    return fb;
}

From source file:Main.java

public static FloatBuffer makeFloatBuffer4(float $a, float $b, float $c, float $d) {
    ByteBuffer b = ByteBuffer.allocateDirect(4 * BYTES_PER_FLOAT);
    b.order(ByteOrder.nativeOrder());
    FloatBuffer buffer = b.asFloatBuffer();
    buffer.put($a);// w  w  w.java  2s  .  co  m
    buffer.put($b);
    buffer.put($c);
    buffer.put($d);
    buffer.position(0);
    return buffer;
}

From source file:Main.java

public static void copyInternal(final FloatBuffer buf, final int fromPos, final int toPos, final int length) {
    final float[] data = new float[length];
    buf.position(fromPos);
    buf.get(data);/*w w w. j  a  v a  2 s .  c o m*/
    buf.position(toPos);
    buf.put(data);
}

From source file:Main.java

public static FloatBuffer createFloatBuffer(FloatBuffer buf) {
    FloatBuffer dest = createFloatBuffer(buf.capacity());
    dest.clear();/*from  w  w w . ja  v  a  2  s. co m*/
    dest.put(buf);
    dest.position(0);
    return dest;
}

From source file:Main.java

public static FloatBuffer createFloatBuffer(FloatBuffer buffer) {
    FloatBuffer dest = createFloatBuffer(buffer.capacity());
    dest.clear();/*  ww w  .j a  v a 2 s.c  o m*/
    dest.put(buffer);
    dest.position(0);
    return dest;
}