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
/** * Creates a {@link FloatBuffer} based on the given data. * * @param data the data for the buffer/*from w w w . j av a2 s . c om*/ * @return the float buffer */ public static FloatBuffer createFloatBuffer(final float[] data) { ByteBuffer bbVertices = ByteBuffer.allocateDirect(data.length * 4); bbVertices.order(ByteOrder.nativeOrder()); final FloatBuffer fBuffer = bbVertices.asFloatBuffer(); fBuffer.put(data); fBuffer.position(0); return fBuffer; }
From source file:Main.java
/** * <p>//from ww w . j a v a 2s . c om * Creates a new byte buffer whose content is a shared subsequence of this * buffer's content. * </p> * <p> * The content of the new buffer will start at this buffer's current position. * Changes to this buffer's content will be visible in the new buffer, and * vice versa; the two buffers' position, limit, and mark values will be * independent. The utility method also preserves the byte order of the source * buffer into the new buffer. * </p> * <p> * The new buffer's position will be zero, its capacity and its limit will be * the number of bytes remaining in this buffer, and its mark will be * undefined. The new buffer will be direct if, and only if, this buffer is * direct, and it will be read-only if, and only if, this buffer is read-only. * </p> * * @param buffer * source buffer * @return new buffer */ public static ByteBuffer slice(ByteBuffer buffer) { final ByteOrder o = buffer.order(); final ByteBuffer r = buffer.slice(); r.order(o); return r; }
From source file:Main.java
public static ByteBuffer newByteBuffer(int numElements) { ByteBuffer bb = ByteBuffer.allocateDirect(numElements); bb.order(ByteOrder.nativeOrder()); return bb;// w ww. j av a2 s .c o m }
From source file:Main.java
public static FloatBuffer createFloatBuffer(float[] triangleCoords) { FloatBuffer vertexbuffer;/* w w w .ja v a 2s. c o m*/ ByteBuffer bb = ByteBuffer.allocateDirect(triangleCoords.length * 4);// 9*4 bb.order(ByteOrder.nativeOrder()); vertexbuffer = bb.asFloatBuffer(); vertexbuffer.put(triangleCoords); vertexbuffer.position(0); return vertexbuffer; }
From source file:Main.java
public static ShortBuffer makeShortBuffer(short[] array) { if (array == null) throw new IllegalArgumentException(); ByteBuffer byteBuffer = ByteBuffer.allocateDirect(2 * array.length); byteBuffer.order(ByteOrder.nativeOrder()); ShortBuffer shortBuffer = byteBuffer.asShortBuffer(); shortBuffer.put(array);/*from w ww.jav a 2 s. com*/ shortBuffer.position(0); return shortBuffer; }
From source file:Main.java
/** * <p>//w w w . j av a 2 s.c o m * Creates a new, read-only byte buffer that shares this buffer's content. * </p> * <p> * The content of the new buffer will be that of this buffer. Changes to this * buffer's content will be visible in the new buffer; the new buffer itself, * however, will be read-only and will not allow the shared content to be * modified. The two buffers' position, limit, and mark values will be * independent. Its byte order will be preserved. * </p> * <p> * The new buffer's capacity, limit, position, and mark values will be * identical to those of this buffer. * </p> * <p> * If this buffer is itself read-only then this method behaves in exactly the * same way as the duplicate method. * </p> * * @param buffer * source buffer * @return new buffer */ public static ByteBuffer asReadonly(ByteBuffer buffer) { final ByteOrder o = buffer.order(); final ByteBuffer r = buffer.asReadOnlyBuffer(); r.order(o); return r; }
From source file:Main.java
public static FloatBuffer toFloatBufferPositionZero(float[] values) { ByteBuffer vbb = ByteBuffer.allocateDirect(values.length * 4); vbb.order(ByteOrder.nativeOrder()); FloatBuffer buffer = vbb.asFloatBuffer(); buffer.put(values);//from w ww . j a v a2s .c om buffer.position(0); return buffer; }
From source file:Main.java
public static ByteBuffer makeByteBuffer(byte[] array) /* */ {//from w w w . j av a2 s .c o m /* 63 */int SIZE = 1; /* 64 */ByteBuffer byteBuffer = ByteBuffer.allocateDirect(array.length * 1); /* 65 */byteBuffer.order(ByteOrder.nativeOrder()); /* 66 */byteBuffer.put(array); /* 67 */byteBuffer.position(0); /* 68 */return byteBuffer; /* */}
From source file:Main.java
public static FloatBuffer transportArrayToNativeBuffer(float[] fArray) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(fArray.length * 4); byteBuffer.order(ByteOrder.nativeOrder()); return (FloatBuffer) byteBuffer.asFloatBuffer().put(fArray).position(0); }
From source file:Main.java
public static IntBuffer transportArrayToNativeBuffer(int[] iArray) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(iArray.length * 4); byteBuffer.order(ByteOrder.nativeOrder()); return (IntBuffer) byteBuffer.asIntBuffer().put(iArray).position(0); }