Example usage for java.nio ByteOrder nativeOrder

List of usage examples for java.nio ByteOrder nativeOrder

Introduction

In this page you can find the example usage for java.nio ByteOrder nativeOrder.

Prototype

public static ByteOrder nativeOrder() 

Source Link

Document

Returns the current platform byte order.

Usage

From source file:Main.java

public static FloatBuffer floatArrayToNativeFloatBuffer(float[] floats) {
    FloatBuffer floatBuffer = ByteBuffer.allocateDirect(floats.length * 4).order(ByteOrder.nativeOrder())
            .asFloatBuffer();// ww w  .ja v a  2 s .  c o m
    floatBuffer.put(floats).position(0);
    return floatBuffer;
}

From source file:Main.java

public static IntBuffer arrayToIntBuffer(int[] inputArray) {
    IntBuffer iBuf = ByteBuffer.allocateDirect(inputArray.length * BYTES_PER_INT).order(ByteOrder.nativeOrder())
            .asIntBuffer();//  w ww. ja  va 2 s .  co  m
    iBuf.put(inputArray).position(0);
    return iBuf;
}

From source file:Main.java

public static ShortBuffer createShortBuffer(short[] data) {
    ShortBuffer sb = ByteBuffer.allocateDirect(data.length * BYTES_PER_SHORT).order(ByteOrder.nativeOrder())
            .asShortBuffer();//from w w  w.  j a v  a 2s .  co m
    sb.put(data).position(0);
    return sb;
}

From source file:Main.java

public static FloatBuffer createFloatBuffer(float[] triangleCoords) {
    FloatBuffer vertexbuffer;//from w  ww  . j  av  a  2 s .c  o m
    ByteBuffer bb = ByteBuffer.allocateDirect(triangleCoords.length * 4);// 9*4
    bb.order(ByteOrder.nativeOrder());
    vertexbuffer = bb.asFloatBuffer();
    vertexbuffer.put(triangleCoords);
    vertexbuffer.position(0);
    return vertexbuffer;
}

From source file:Main.java

public static ByteBuffer makeByteBuffer(byte[] array) {
    if (array == null)
        throw new IllegalArgumentException();

    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(array.length);
    byteBuffer.order(ByteOrder.nativeOrder());
    byteBuffer.put(array);//w w  w  .j a  v a 2s.c o m
    byteBuffer.position(0);
    return byteBuffer;
}

From source file:Main.java

public static FloatBuffer createFloatBuffer(int size) {
    ByteBuffer buffer = ByteBuffer.allocateDirect(size * BYTES_PER_FLOAT);
    buffer.order(ByteOrder.nativeOrder());
    return buffer.asFloatBuffer();
}

From source file:Main.java

/**
 * // w  w w  .  j  a va 2 s  .  c o  m
 * @param arr
 * @return
 */
public static final ByteBuffer createByteBuffer(byte[] arr) {
    int len = sizeofB(arr.length);
    ByteBuffer bb = ByteBuffer.allocateDirect(len);
    bb.order(ByteOrder.nativeOrder());
    ByteBuffer fb = bb;
    fb.put(arr);
    fb.position(0);
    return fb;
}

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);//from www .j a  va  2  s . c o m
    buffer.put($b);
    buffer.put($c);
    buffer.position(0);
    return buffer;
}

From source file:Main.java

public static ByteBuffer createByteBuffer(int size) {
    return ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());
}

From source file:Main.java

public static FloatBuffer toFloatBuffer(final float[] data) {
    final FloatBuffer buffer = ByteBuffer.allocateDirect(data.length * FLOAT_SIZE_BYTES)
            .order(ByteOrder.nativeOrder()).asFloatBuffer();
    buffer.put(data).position(0);/*w w w  .j av a2 s .co m*/
    return buffer;
}