List of usage examples for java.nio IntBuffer put
public IntBuffer put(IntBuffer src)
From source file:MainClass.java
public static void main(String[] args) throws IOException { FileChannel fc = new RandomAccessFile(new File("temp.tmp"), "rw").getChannel(); IntBuffer ib = fc.map(FileChannel.MapMode.READ_WRITE, 0, fc.size()).asIntBuffer(); ib.put(0); for (int i = 1; i < 10; i++) ib.put(ib.get(i - 1));//from w ww. j ava2 s . c o m fc.close(); }
From source file:IntBufferDemo.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); IntBuffer ib = bb.asIntBuffer(); // Store an array of int: ib.put(new int[] { 11, 42, 47, 99, 143, 811, 1016 }); // Absolute location read and write: System.out.println(ib.get(3)); ib.put(3, 1811);/*w ww . ja v a 2s .c o m*/ ib.rewind(); while (ib.hasRemaining()) { int i = ib.get(); if (i == 0) break; // Else we'll get the entire buffer System.out.println(i); } }
From source file:MainClass.java
public static void main(String[] args) throws IOException { FileChannel fc = new RandomAccessFile("temp.tmp", "rw").getChannel(); IntBuffer ib = fc.map(FileChannel.MapMode.READ_WRITE, 0, fc.size()).asIntBuffer(); for (int i = 0; i < 10; i++) ib.put(i); fc.close();//from w w w. j a v a 2 s .c om }
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); intBuffer.position(0);/*from w w w.ja v a2 s. c o m*/ return intBuffer; }
From source file:Main.java
public static IntBuffer makeBuffer(int[] data) { ByteBuffer b = ByteBuffer.allocateDirect(data.length * 4); b.order(ByteOrder.nativeOrder()); IntBuffer buffer = b.asIntBuffer(); buffer.put(data); buffer.position(0);/*from w w w. j ava 2 s . c om*/ return buffer; }
From source file:Main.java
public static IntBuffer intArrayToBuffer(int[] intArray) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(intArray.length * 4); byteBuffer.order(ByteOrder.nativeOrder()); IntBuffer intBuffer = byteBuffer.asIntBuffer(); intBuffer.put(intArray); intBuffer.position(0);//from ww w . ja v a 2s . c om return intBuffer; }
From source file:Main.java
public static IntBuffer makeIntBuffer(int[] array) /* */ {//from w w w . j a v a 2 s.co 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
/** * Creates a {@link IntBuffer} based on the given data. * * @param data the data for the buffer/* w w w .java 2s . c o m*/ * @return the int buffer */ public static IntBuffer createIntBuffer(final float[] data) { final int[] tmpData = new int[data.length]; for (int i = 0; i < tmpData.length; i++) { tmpData[i] = Float.floatToRawIntBits(data[i]); } final ByteBuffer bbVertices = ByteBuffer.allocateDirect(tmpData.length * 4); bbVertices.order(ByteOrder.nativeOrder()); final IntBuffer intBuffer = bbVertices.asIntBuffer(); intBuffer.put(tmpData); intBuffer.flip(); return intBuffer; }
From source file:Main.java
/**buffer methods*/ public static IntBuffer makeIntBuffer(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); intBuffer.position(0);//from ww w. jav a 2s. co m return intBuffer; }
From source file:Main.java
public static IntBuffer getBufferFromIntArray(int[] array) { IntBuffer result = ByteBuffer.allocateDirect(array.length * 4).order(ByteOrder.nativeOrder()).asIntBuffer(); result.put(array).position(0); return result; }