List of usage examples for java.nio ByteBuffer asIntBuffer
public abstract IntBuffer asIntBuffer();
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); }
From source file:Main.java
public static IntBuffer makeIntBuffer(int[] array) /* */ {/*from w w w. j a va 2 s .c om*/ /* 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//from ww w . j a va2 s. 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);/*from www .j a v a 2s .c o m*/ intBuffer.position(0); return intBuffer; }
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);/*w ww . j av a2s .c om*/ intBuffer.position(0); return intBuffer; }
From source file:org.bimserver.utils.BinUtils.java
public static byte[] intToByteArray(int inInt) { byte[] bArray = new byte[4]; ByteBuffer bBuffer = ByteBuffer.wrap(bArray); IntBuffer lBuffer = bBuffer.asIntBuffer(); lBuffer.put(inInt);/*from ww w .j a v a 2 s . com*/ return bArray; }
From source file:de.ailis.threedee.utils.BufferUtils.java
/** * Creates a direct integer buffer with native byte order. * * @param size//from ww w. j a v a 2 s . c om * The data * @return The created direct integer buffer */ public static IntBuffer createDirectIntegerBuffer(final int size) { final ByteBuffer tmp = ByteBuffer.allocateDirect(size * INTEGER_BYTES); tmp.order(ByteOrder.nativeOrder()); return tmp.asIntBuffer(); }
From source file:de.ailis.threedee.utils.BufferUtils.java
/** * Converts the specified integer buffer to native endian and returns this * new buffer. If buffer is already in correct endian format then it is * returned right away.// www . j ava 2 s .c o m * * @param buffer * The integer buffer to convert * @return The converted integer buffer or the source buffer if no * conversion is needed */ public static IntBuffer convertToNativeEndian(final IntBuffer buffer) { if (buffer.order() == ByteOrder.nativeOrder()) return buffer; final ByteBuffer bytes = ByteBuffer.allocateDirect(buffer.capacity()); bytes.order(ByteOrder.nativeOrder()); final IntBuffer ints = bytes.asIntBuffer(); ints.put(buffer).rewind(); return ints; }
From source file:org.grouplens.lenskit.data.dao.packed.BinaryIndexTable.java
/** * Create a binary index table./*from w w w . j a v a 2 s . c om*/ * @param nentries The number of entries in the table. * @param buffer The table buffer. Its position will be advanced to the end of the table. * @return The index table. */ public static BinaryIndexTable fromBuffer(int nentries, ByteBuffer buffer) { logger.debug("reading table of {} entries", nentries); long[] keys = new long[nentries]; int[] offsets = new int[nentries]; int[] sizes = new int[nentries]; int nextExpectedOffset = 0; for (int i = 0; i < nentries; i++) { keys[i] = buffer.getLong(); if (i > 0 && keys[i - 1] >= keys[i]) { logger.error("key {} is not greater than previous key {}", keys[i], keys[i - 1]); throw new IllegalArgumentException("corrupted index table"); } offsets[i] = buffer.getInt(); sizes[i] = buffer.getInt(); if (offsets[i] != nextExpectedOffset) { logger.error("expected offset {}, got {}", nextExpectedOffset, offsets[i]); throw new IllegalArgumentException("corrupted index table"); } nextExpectedOffset += sizes[i]; } if (buffer.remaining() < nextExpectedOffset) { throw new IllegalArgumentException("buffer not large enough"); } int end = buffer.position() + nextExpectedOffset * 4; ByteBuffer dup = buffer.duplicate(); dup.limit(end); buffer.position(end); LongKeyDomain dom = LongKeyDomain.wrap(keys, keys.length, true); return new BinaryIndexTable(dom, offsets, sizes, dup.asIntBuffer()); }
From source file:com.atilika.kuromoji.trie.DoubleArrayTrie.java
/** * Load Stored data/* w ww .ja v a 2 s.c om*/ * * @param input input stream to read the double array trie from * @return double array trie, not null * @throws IOException if an IO error occured during reading the double array trie */ public static DoubleArrayTrie read(InputStream input) throws IOException { DoubleArrayTrie trie = new DoubleArrayTrie(); DataInputStream dis = new DataInputStream(new BufferedInputStream(input)); trie.compact = dis.readBoolean(); int baseCheckSize = dis.readInt(); // Read size of baseArr and checkArr int tailSize = dis.readInt(); // Read size of tailArr ReadableByteChannel channel = Channels.newChannel(dis); ByteBuffer tmpBaseBuffer = ByteBuffer.allocate(baseCheckSize * 4); channel.read(tmpBaseBuffer); tmpBaseBuffer.rewind(); trie.baseBuffer = tmpBaseBuffer.asIntBuffer(); ByteBuffer tmpCheckBuffer = ByteBuffer.allocate(baseCheckSize * 4); channel.read(tmpCheckBuffer); tmpCheckBuffer.rewind(); trie.checkBuffer = tmpCheckBuffer.asIntBuffer(); ByteBuffer tmpTailBuffer = ByteBuffer.allocate(tailSize * 2); channel.read(tmpTailBuffer); tmpTailBuffer.rewind(); trie.tailBuffer = tmpTailBuffer.asCharBuffer(); input.close(); return trie; }