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 ByteBuffer createByteBuffer(int count) { ByteBuffer data = ByteBuffer.allocateDirect(count * 4); data.order(ByteOrder.nativeOrder()); return data;//from w ww.j a v a2 s . c o m }
From source file:Main.java
public static IntBuffer newIntBuffer(int numInts) { ByteBuffer buffer = ByteBuffer.allocate(numInts * 4); buffer.order(ByteOrder.nativeOrder()); return buffer.asIntBuffer(); }
From source file:Main.java
public static LongBuffer newLongBuffer(int numLongs) { ByteBuffer buffer = ByteBuffer.allocate(numLongs * 8); buffer.order(ByteOrder.nativeOrder()); return buffer.asLongBuffer(); }
From source file:Main.java
/** * @param size number of chars the buffer should hold * @return the newly allocated char buffer *//*from w w w . j a va 2s .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 buffer//w w w . j a va 2 s . c om * @return */ public static ByteBuffer duplicate(ByteBuffer buffer) { final ByteBuffer r = buffer.duplicate(); r.order(buffer.order()); return r; }
From source file:Main.java
public static int readInt(InputStream inputStream) throws IOException { byte[] bytesToRead = new byte[4]; inputStream.read(bytesToRead);/*from w w w. ja va2 s . c o m*/ ByteBuffer buffer = ByteBuffer.wrap(bytesToRead); buffer.order(ByteOrder.LITTLE_ENDIAN); return buffer.getInt(); }
From source file:Main.java
/** * @param size number of floats the buffer should hold * @return the newly allocated float buffer *///from w w w. 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
public static int byteArrayToLeInt(byte[] b) { final ByteBuffer bb = ByteBuffer.wrap(b); bb.order(ByteOrder.LITTLE_ENDIAN); return bb.getInt(); }
From source file:Main.java
public static long ReadlittleEndianLong(InputStream dis) throws IOException { byte[] bytes = new byte[8]; int re = dis.read(bytes); if (re == -1) { return -1; }/*from ww w .ja va2 s .co m*/ ByteBuffer bytebuffer = ByteBuffer.wrap(bytes); bytebuffer.order(ByteOrder.LITTLE_ENDIAN); long result = bytebuffer.getLong(); return result; }
From source file:Main.java
public static String bytesToUuid(byte[] bytes) { ByteBuffer bb = ByteBuffer.wrap(bytes); bb.order(ByteOrder.LITTLE_ENDIAN); long lsb = bb.getLong(); long msb = bb.getLong(); UUID uuid = new UUID(msb, lsb); return uuidToString(uuid); }