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 IntBuffer makeIntBuffer(int[] array)
/*     */ {/* ww  w .  j a  v  a2s.c o  m*/
    /*  52 */int integerSize = 4;
    /*  53 */ByteBuffer byteBuffer = ByteBuffer.allocateDirect(array.length * 4);
    /*  54 */byteBuffer.order(ByteOrder.nativeOrder());
    /*  55 */IntBuffer intBuffer = byteBuffer.asIntBuffer();
    /*  56 */intBuffer.put(array);
    /*  57 */intBuffer.position(0);
    /*  58 */return intBuffer;
    /*     */}

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 ww. ja v a  2  s  . com*/
    buffer.put($b);
    buffer.put($c);
    buffer.put($d);
    buffer.position(0);
    return buffer;
}

From source file:Main.java

/**
 * //  w  w  w  .  j  a v  a 2s  .  co  m
 * @since 1.0.0
 * @param v
 * @return the FloatBuffer
 */
public static FloatBuffer toFloatBuffer(float[] v) {
    ByteBuffer buf = ByteBuffer.allocateDirect(v.length * 4);
    buf.order(ByteOrder.nativeOrder());
    FloatBuffer buffer = buf.asFloatBuffer();
    buffer.put(v);
    buffer.position(0);
    return buffer;
}

From source file:Main.java

/**
 * //from www . ja  va 2  s  . c o  m
 * @since 1.0.0
 * @param v
 * @return the ShortBuffer
 */
public static ShortBuffer toShortBuffer(short[] v) {
    ByteBuffer buf = ByteBuffer.allocateDirect(v.length * 2);
    buf.order(ByteOrder.nativeOrder());
    ShortBuffer buffer = buf.asShortBuffer();
    buffer.put(v);
    buffer.position(0);
    return buffer;
}

From source file:Main.java

public static FloatBuffer transportArrayToNativeBuffer(float[] fArray) {
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(fArray.length * 4);
    byteBuffer.order(ByteOrder.nativeOrder());
    return (FloatBuffer) byteBuffer.asFloatBuffer().put(fArray).position(0);
}

From source file:Main.java

/**
 * @param pCapacity the capacity of the returned {@link FloatBuffer} in floats.
 * @return//from w ww.  ja  v  a 2 s.  co m
 */
public static FloatBuffer allocateDirectFloatBuffer(final int pCapacity) {
    return ByteBuffer.allocateDirect(pCapacity * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
}

From source file:Main.java

public static ShortBuffer makeShortBuffer(short[] array) {
    if (array == null)
        throw new IllegalArgumentException();

    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(2 * array.length);
    byteBuffer.order(ByteOrder.nativeOrder());
    ShortBuffer shortBuffer = byteBuffer.asShortBuffer();
    shortBuffer.put(array);/*  w  ww.j ava2 s.c  o  m*/
    shortBuffer.position(0);
    return shortBuffer;
}

From source file:Main.java

/**
 * @param size number of chars the buffer should hold
 * @return the newly allocated char buffer
 *///w w w .java2  s .c o  m
public static CharBuffer createCharBuffer(int size) {
    ByteBuffer bb = ByteBuffer.allocateDirect(2 * size);
    bb.order(ByteOrder.nativeOrder());
    return bb.asCharBuffer();
}

From source file:Main.java

/**
 * @param size number of floats the buffer should hold
 * @return the newly allocated float buffer
 *///  www. j av  a  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

/**
 * Make a direct NIO ByteBuffer from an array of floats
 * @param arr The array/*  w  w w .ja v a  2 s  .  c o  m*/
 * @return The newly created FloatBuffer
 */
public static ByteBuffer makeByteBuffer(byte[] arr) {
    ByteBuffer bb = ByteBuffer.allocateDirect(arr.length);
    bb.order(ByteOrder.nativeOrder());
    bb.put(arr);
    bb.position(0);
    return bb;
}