List of usage examples for java.nio ByteBuffer order
Endianness order
To view the source code for java.nio ByteBuffer order.
Click Source Link
From source file:Main.java
public static ShortBuffer toShortBuffer(short[] v) { ByteBuffer buff = ByteBuffer.allocateDirect(v.length * 2); buff.order(ByteOrder.nativeOrder()); ShortBuffer buffer = buff.asShortBuffer(); buffer.put(v);/* www. j a va2 s . c o m*/ buffer.position(0); return buffer; }
From source file:Main.java
public static IntBuffer getIntBuffer(int[] coords) { ByteBuffer bb = ByteBuffer.allocateDirect(coords.length * 4); bb.order(ByteOrder.nativeOrder()); IntBuffer intBuffer = bb.asIntBuffer(); intBuffer.put(coords);/*from w w w . ja v a 2s . com*/ intBuffer.position(0); return intBuffer; }
From source file:Main.java
public static ShortBuffer getShortBuffer(short[] coords) { ByteBuffer bb = ByteBuffer.allocateDirect(coords.length * 2); bb.order(ByteOrder.nativeOrder()); ShortBuffer shortBuffer = bb.asShortBuffer(); shortBuffer.put(coords);//from w ww . j a v a 2 s .c o m shortBuffer.position(0); return shortBuffer; }
From source file:Main.java
public static byte[] uuidToBytes(String uuidStr) { UUID uuid = stringToUuid(uuidStr); ByteBuffer bb = ByteBuffer.allocate(16); bb.order(ByteOrder.LITTLE_ENDIAN); bb.putLong(uuid.getLeastSignificantBits()); bb.putLong(uuid.getMostSignificantBits()); return bb.array(); }
From source file:Main.java
/** * Make a direct NIO ByteBuffer from an array of floats * @param arr The array//from ww w .j ava 2s. 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; }
From source file:Main.java
public static FloatBuffer allocateFloatBuffer(int capacity) { ByteBuffer vbb = ByteBuffer.allocateDirect(capacity); vbb.order(ByteOrder.nativeOrder()); return vbb.asFloatBuffer(); }
From source file:Main.java
public static byte[] intToByteArray(int value) { ByteBuffer buffer = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE); buffer.order(ByteOrder.BIG_ENDIAN); buffer.putInt(value);//from www . j ava 2 s. co m return buffer.array(); }
From source file:Main.java
/** * /*from w ww . ja 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 byte[] intToByteArrayLE(int value) { ByteBuffer buffer = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE); buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putInt(value);/*from w w w. j av a2s . c o m*/ return buffer.array(); }
From source file:Main.java
public static ShortBuffer allocateShortBuffer(int capacity) { ByteBuffer vbb = ByteBuffer.allocateDirect(capacity); vbb.order(ByteOrder.nativeOrder()); return vbb.asShortBuffer(); }