List of usage examples for java.nio ByteBuffer putInt
public abstract ByteBuffer putInt(int value);
From source file:Main.java
public static byte[] getIntArray(int val) { ByteBuffer typeBuffer = ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN); typeBuffer.putInt(val); return typeBuffer.array(); }
From source file:Main.java
public static void putMessageLength(byte[] message) { ByteBuffer lengthBuffer = ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN); lengthBuffer.putInt(message.length); byte[] lenArray = lengthBuffer.array(); for (int i = 0; i < 4; i++) message[i] = lenArray[i];//from ww w .j av a 2 s . c o m }
From source file:Main.java
/** * Converts a given integer to byte, in little endian * @param i An integer to be converted to byte * @return A byte array stores byte representation of given integer *//*from w ww . j a va 2s . c o m*/ public static byte[] intToByte(int i) { ByteBuffer b = ByteBuffer.allocate(4); b.order(ByteOrder.LITTLE_ENDIAN); b.putInt(i); byte buf[] = b.array(); return buf; }
From source file:Main.java
public static byte[] intToByteArray(int value) { ByteBuffer buffer = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE); buffer.order(ByteOrder.BIG_ENDIAN); buffer.putInt(value); return buffer.array(); }
From source file:Main.java
public static byte[] intToByteArrayLE(int value) { ByteBuffer buffer = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE); buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putInt(value); return buffer.array(); }
From source file:org.cloudata.core.commitlog.CommitLogWritableUtils.java
public static void writeStringArray(ByteBuffer buf, String[] array) { buf.putInt(array.length); for (int i = 0; i < array.length; i++) { writeString(buf, array[i]);//from w ww . j ava 2 s .c o m } }
From source file:Main.java
public static byte[] int2bytes(int a) { int arraySize = Integer.SIZE / Byte.SIZE; ByteBuffer buffer = ByteBuffer.allocate(arraySize); buffer.order(ByteOrder.LITTLE_ENDIAN); return buffer.putInt(a).array(); }
From source file:Main.java
public static byte[] leIntToByteArray(int i) { final ByteBuffer bb = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE); bb.order(ByteOrder.LITTLE_ENDIAN); bb.putInt(i); return bb.array(); }
From source file:com.alvermont.terraj.fracplanet.util.ByteBufferUtils.java
/** * The sizes of Java types are fixed and defined by the language spec so * this shouldn't be necessary but I'm going to do it anyway - so * there!/*from w w w . jav a 2 s .c o m*/ * * @return The number of bytes occupied by an int value */ public static int sizeofInt() { final ByteBuffer buffer = ByteBuffer.allocate(10); buffer.putInt(0); return buffer.position(); }
From source file:org.cloudata.core.commitlog.CommitLogWritableUtils.java
public static void writeString(ByteBuffer buf, String s) { byte[] sBytes = s.getBytes(); buf.putInt(sBytes.length); buf.put(sBytes);/*from www . j a v a 2s.c o m*/ }