Example usage for java.nio ByteBuffer order

List of usage examples for java.nio ByteBuffer order

Introduction

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

Prototype

Endianness order

To view the source code for java.nio ByteBuffer order.

Click Source Link

Document

The byte order of this buffer, default is BIG_ENDIAN .

Usage

From source file:Main.java

/**
 * /*from w w w  . ja va2  s. c o  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

public static ByteBuffer newByteBuffer(int numBytes) {
    ByteBuffer buffer = ByteBuffer.allocateDirect(numBytes);
    buffer.order(ByteOrder.nativeOrder());
    return buffer;
}

From source file:Main.java

public static IntBuffer allocateInttBuffer(int capacity) {
    ByteBuffer vbb = ByteBuffer.allocateDirect(capacity);
    vbb.order(ByteOrder.nativeOrder());
    return vbb.asIntBuffer();
}

From source file:Main.java

/**
 * Make a direct NIO FloatBuffer from an array of floats
 * @param arr The array//from w w w.jav  a2  s  .  com
 * @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;
}

From source file:Main.java

/**
 * //from  w  w w.ja va2s  . c  om
 * @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 ShortBuffer buildShortBuffer(short[] array) {
    ByteBuffer byteBuf = ByteBuffer.allocateDirect(array.length * 2);
    byteBuf.order(ByteOrder.nativeOrder());
    ShortBuffer buffer = byteBuf.asShortBuffer();
    buffer.put(array);//from  w  ww. j  a v  a2s .co m
    buffer.position(0);
    return buffer;
}

From source file:Main.java

public static byte[] int2bytes(int a) {
    int arraySize = Integer.SIZE / Byte.SIZE;
    ByteBuffer buffer = ByteBuffer.allocate(arraySize);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    return buffer.putInt(a).array();
}

From source file:Main.java

public static IntBuffer createIntBuffer(int count) {
    ByteBuffer data = ByteBuffer.allocateDirect(count * 4);
    data.order(ByteOrder.nativeOrder());
    IntBuffer p1 = data.asIntBuffer();
    return p1;/*from  w w w  .ja  v  a2 s  .c  o m*/
}

From source file:Main.java

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

From source file:Main.java

public static IntBuffer makeBuffer(int[] data) {
    ByteBuffer b = ByteBuffer.allocateDirect(data.length * 4);
    b.order(ByteOrder.nativeOrder());
    IntBuffer buffer = b.asIntBuffer();
    buffer.put(data);/*from   w  w w.  j  a  v  a 2 s.  c  om*/
    buffer.position(0);
    return buffer;
}