List of usage examples for java.nio ByteBuffer getInt
public abstract int getInt();
From source file:Main.java
public static int byteArrayToInt(byte[] bytes) { final ByteBuffer bb = ByteBuffer.wrap(bytes); //bb.order(ByteOrder.LITTLE_ENDIAN); return bb.getInt(); }
From source file:Main.java
public static int byteArrayToInt(byte[] bytes) throws IllegalArgumentException { if (bytes.length != (Integer.SIZE / Byte.SIZE)) { throw new IllegalArgumentException("Incorrect array size to convert to an int"); }/*from w w w .j a v a 2 s .c om*/ ByteBuffer buffer = ByteBuffer.wrap(bytes); buffer.order(ByteOrder.BIG_ENDIAN); return buffer.getInt(); }
From source file:Main.java
public static int byteArrayToIntLE(byte[] bytes) throws IllegalArgumentException { if (bytes.length != (Integer.SIZE / Byte.SIZE)) { throw new IllegalArgumentException("Incorrect array size to convert to an int"); }/*from w w w. ja v a2s. c o m*/ ByteBuffer buffer = ByteBuffer.wrap(bytes); buffer.order(ByteOrder.LITTLE_ENDIAN); return buffer.getInt(); }
From source file:Main.java
public static int byteArrayToLeInt(byte[] b) { final ByteBuffer bb = ByteBuffer.wrap(b); bb.order(ByteOrder.LITTLE_ENDIAN); return bb.getInt(); }
From source file:Main.java
public static int readInt(InputStream inputStream) throws IOException { byte[] bytesToRead = new byte[4]; inputStream.read(bytesToRead);/*w w w .j ava 2 s . co m*/ ByteBuffer buffer = ByteBuffer.wrap(bytesToRead); buffer.order(ByteOrder.LITTLE_ENDIAN); return buffer.getInt(); }
From source file:Main.java
/** * Converts an array of 4 bytes into a int. * * @param bytes The bytes.//from w w w .j av a2 s . c o m * @return The int. */ public static int bytesToInt(final byte[] bytes) { final ByteBuffer buffer = ByteBuffer.allocate(4); buffer.put(bytes, 0, 4); buffer.flip(); return buffer.getInt(); }
From source file:org.cloudata.core.commitlog.CommitLogWritableUtils.java
public static String readString(ByteBuffer buf) { int stringLength = buf.getInt(); byte[] stringBuf = new byte[stringLength]; buf.get(stringBuf);/* w w w . java2 s . c om*/ return new String(stringBuf); }
From source file:org.cloudata.core.commitlog.CommitLogWritableUtils.java
public static String[] readStringArray(ByteBuffer buf) { int length = buf.getInt(); if (length > 1000000) { LOG.warn("the length in unmarshalling string array is too big : " + length); }//www . j a va 2 s. c om String[] ret = new String[length]; for (int i = 0; i < length; i++) { ret[i] = readString(buf); } return ret; }
From source file:Main.java
public static int readInt(byte[] message, int start) { /* Read in the type */ ByteBuffer typeBuffer = ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN); typeBuffer.put(message, start, 4).position(0); return typeBuffer.getInt(); }
From source file:com.sm.replica.ParaList.java
public static ParaList toParaList(byte[] bytes) { ByteBuffer buf = ByteBuffer.wrap(bytes); int size = buf.getInt(); ArrayList<StoreParas> list = new ArrayList<StoreParas>(size); for (int i = 0; i < size; i++) { // length of StoreParas int s = buf.getInt(); byte[] ds = new byte[s]; buf.get(ds);/*from w w w . java 2s . c om*/ list.add(toStoreParas(ds)); } return new ParaList(list); }