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

public static ShortBuffer transportArrayToNativeBuffer(short[] sArray) {
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(sArray.length * 2);
    byteBuffer.order(ByteOrder.nativeOrder());
    return (ShortBuffer) byteBuffer.asShortBuffer().put(sArray).position(0);
}

From source file:Main.java

public static ShortBuffer toShortBuffer(short[] values) {
    ByteBuffer vbb = ByteBuffer.allocateDirect(values.length * 2);
    vbb.order(ByteOrder.nativeOrder());
    ShortBuffer buffer = vbb.asShortBuffer();
    buffer.put(values);/*from  w  w  w .jav a 2  s . c  o m*/
    buffer.position(0);
    return buffer;
}

From source file:Main.java

public static byte[] leIntToByteArray(int i) {
    final ByteBuffer bb = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    bb.putInt(i);// w  w  w  .  j a v  a 2  s  . co  m
    return bb.array();
}

From source file:Main.java

/**
 * Relative <em>get</em> method for reading {@code size} number of bytes from the current
 * position of this buffer.//from   w  ww . jav a2s. c om
 * <p>
 * <p>This method reads the next {@code size} bytes at this buffer's current position,
 * returning them as a {@code ByteBuffer} with start set to 0, limit and capacity set to
 * {@code size}, byte order set to this buffer's byte order; and then increments the position by
 * {@code size}.
 */
private static ByteBuffer getByteBuffer(final ByteBuffer source, final int size)
        throws BufferUnderflowException {
    if (size < 0) {
        throw new IllegalArgumentException("size: " + size);
    }
    final int originalLimit = source.limit();
    final int position = source.position();
    final int limit = position + size;
    if ((limit < position) || (limit > originalLimit)) {
        throw new BufferUnderflowException();
    }
    source.limit(limit);
    try {
        final ByteBuffer result = source.slice();
        result.order(source.order());
        source.position(limit);
        return result;
    } finally {
        source.limit(originalLimit);
    }
}

From source file:Main.java

/**
 * Creates a {@link ShortBuffer} based on the given data.
 *
 * @param data the data for the buffer//from  w ww.j  a v a 2  s. com
 * @return the short buffer
 */
public static ShortBuffer createShortBuffer(final short[] data) {
    if (data == null) {
        return null;
    }
    ByteBuffer bbVertices = ByteBuffer.allocateDirect(data.length * 4);
    bbVertices.order(ByteOrder.nativeOrder());
    final ShortBuffer fBuffer = bbVertices.asShortBuffer();
    fBuffer.put(data);
    fBuffer.position(0);
    return fBuffer;
}

From source file:Main.java

public static IntBuffer makeIntBuffer(int[] array)
/*     */ {/*from w ww.  j  a v  a 2 s .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 toFloatBufferPositionZero(float[] values) {
    final ByteBuffer vbb = ByteBuffer.allocateDirect(values.length * 4);
    vbb.order(ByteOrder.nativeOrder());
    final FloatBuffer buffer = vbb.asFloatBuffer();
    buffer.put(values);/*  w w  w .  j av a  2  s  . c o  m*/
    buffer.position(0);
    return buffer;
}

From source file:Main.java

/**
 * create a Floatbuffer for a given Array
 * @param array//w  w w.j av  a2s  .  co m
 * @return
 */
public static FloatBuffer createFloatBuffer(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);
    floatBuffer.position(0);
    return floatBuffer;
}

From source file:Main.java

/**
 * Make a FloatBuffer from an array of floats
 * //from  w  ww.  j a  v a 2  s. co  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

public static ShortBuffer toShortBuffer(short[] values) {
    final ByteBuffer vbb = ByteBuffer.allocateDirect(values.length * 2);
    vbb.order(ByteOrder.nativeOrder());
    final ShortBuffer buffer = vbb.asShortBuffer();
    buffer.put(values);//from   w  w w  .  j  a va 2  s . c o  m
    buffer.position(0);
    return buffer;
}