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 FloatBuffer makeFloatBuffer(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);/*from ww w . ja va2 s . com*/ floatBuffer.position(0); return floatBuffer; }
From source file:Main.java
public static AdvertiseData createAllOffAdvertiseData() { byte[] manufacturerData = new byte[23]; ByteBuffer bb = ByteBuffer.wrap(manufacturerData); bb.order(ByteOrder.BIG_ENDIAN); bb.put((byte) 0x41); bb.put((byte) 0x6c); bb.put((byte) 0x6c); bb.put((byte) 0x4f); bb.put((byte) 0x66); bb.put((byte) 0x66); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); AdvertiseData.Builder builder = new AdvertiseData.Builder(); builder.addManufacturerData(0x006d, manufacturerData); AdvertiseData adv = builder.build(); return adv;/*w w w . j a v a2 s. co m*/ }
From source file:Main.java
/** create AdvertiseDate for iBeacon */ public static AdvertiseData createLightOnAdvertiseData() { byte[] manufacturerData = new byte[23]; ByteBuffer bb = ByteBuffer.wrap(manufacturerData); bb.order(ByteOrder.BIG_ENDIAN); bb.put((byte) 0x4c); bb.put((byte) 0x69); bb.put((byte) 0x67); bb.put((byte) 0x68); bb.put((byte) 0x74); bb.put((byte) 0x4f); bb.put((byte) 0x6e); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); AdvertiseData.Builder builder = new AdvertiseData.Builder(); builder.addManufacturerData(0x006d, manufacturerData); AdvertiseData adv = builder.build(); return adv;/*from ww w.ja v a 2 s .c o m*/ }
From source file:Main.java
/** create AdvertiseDate for iBeacon */ public static AdvertiseData createAllOnAdvertiseData() { byte[] manufacturerData = new byte[23]; ByteBuffer bb = ByteBuffer.wrap(manufacturerData); bb.order(ByteOrder.BIG_ENDIAN); bb.put((byte) 0x41); bb.put((byte) 0x6c); bb.put((byte) 0x6c); bb.put((byte) 0x4f); bb.put((byte) 0x6e); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); bb.put((byte) 0x00); AdvertiseData.Builder builder = new AdvertiseData.Builder(); builder.addManufacturerData(0x006d, manufacturerData); AdvertiseData adv = builder.build(); return adv;//from w w w . j a v a 2s . c o m }
From source file:Main.java
public static ByteBuffer copy(ByteBuffer buffer) { final int length = buffer.limit() - buffer.position(); final ByteOrder o = buffer.order(); final ByteBuffer r = ByteBuffer.allocate(length); r.order(o);//from w ww . j a v a2 s . c o m r.put(buffer); r.clear(); // Reset position and limit after the put() return r; }
From source file:Main.java
/**android methods*/ //Only for Android public static IntBuffer makeFloatBuffer(int[] array) { final int integerSize = Integer.SIZE / 8; ByteBuffer byteBuffer = ByteBuffer.allocateDirect(array.length * integerSize); byteBuffer.order(ByteOrder.nativeOrder()); IntBuffer intBuffer = byteBuffer.asIntBuffer(); intBuffer.put(array);/*from ww w. j a v a2s. co m*/ intBuffer.position(0); return intBuffer; }
From source file:Main.java
public static Buffer fillBuffer(float[] array) { // Convert to floats because OpenGL doesnt work on doubles, and manually // casting each input value would take too much time. ByteBuffer bb = ByteBuffer.allocateDirect(4 * array.length); // each // float// w w w.j a v a 2s . c o m // takes 4 // bytes bb.order(ByteOrder.LITTLE_ENDIAN); for (float d : array) bb.putFloat(d); bb.rewind(); return bb; }
From source file:Main.java
public static Buffer fillBuffer(double[] array) { // Convert to floats because OpenGL doesnt work on doubles, and manually // casting each input value would take too much time. ByteBuffer bb = ByteBuffer.allocateDirect(4 * array.length); // each // float//from w w w .j a v a 2 s .co m // takes 4 // bytes bb.order(ByteOrder.LITTLE_ENDIAN); for (double d : array) bb.putFloat((float) d); bb.rewind(); return bb; }
From source file:info.gehrels.flockDBClient.ByteHelper.java
static ByteBuffer asByteBuffer(long... destinationIds) { ByteBuffer buf = null; buf = ByteBuffer.wrap(new byte[destinationIds.length * (Long.SIZE / 8)]); buf.order(ByteOrder.LITTLE_ENDIAN); for (long destinationId : destinationIds) { buf.putLong(destinationId);//from w ww . j a v a2s.c o m } buf.rewind(); return buf; }
From source file:Main.java
public static ShortBuffer createShortBuffer(short[] shortData) { ShortBuffer drawListBuffer;/*from w w w . j ava 2 s.c om*/ ByteBuffer dlb = ByteBuffer.allocateDirect( // (# of coordinate values * 2 bytes per short) shortData.length * 2); dlb.order(ByteOrder.nativeOrder()); drawListBuffer = dlb.asShortBuffer(); drawListBuffer.put(shortData); drawListBuffer.position(0); return drawListBuffer; }