Serialization { public static int readInt(byte[] array) { if (array.length != SIZE_OF_INT) { throw new IllegalArgumentException("Required 4 bytes, but was given " + array.length); } return readInt(array, 0); } private  Serialization(); static void saveRecording(Recording recording, Path file); @SuppressWarnings("PMD.ExcessiveMethodLength") static void updateRecordingSave(Recording recording, Path file); static byte[] encode(T value); static byte[] encode(T value, DataType<T> type); static T decode(byte[] buffer, int bufferPosition, DataType<T> type); static Recording loadRecording(Path file); static int sizeOfStringArray(String[] array); static byte[] header(List<TimestampedData> data); static List<String> getAllSourceNames(List<TimestampedData> data); static byte[] toByteArray(boolean val); static byte[] toByteArray(byte val); static byte[] toByteArray(short val); static byte[] toByteArray(int val); static byte[] toByteArray(long val); static byte[] toByteArray(double val); static byte[] toByteArray(String string); static byte[] toByteArray(String[] array); @Deprecated static byte[] subArray(byte[] raw, int start, int end); static void put(byte[] dst, byte[] src, int pos); static boolean readBoolean(byte[] array); static boolean readBoolean(byte[] array, int pos); static short readShort(byte[] array); static short readShort(byte[] array, int pos); static int readInt(byte[] array); static int readInt(byte[] array, int pos); static long readLong(byte[] array); static long readLong(byte[] array, int pos); static double readDouble(byte[] array, int pos); static String readString(byte[] array, int pos); static String[] readStringArray(byte[] array, int pos); static final int MAGIC_NUMBER; static final int VERSION; static final int SIZE_OF_BYTE; static final int SIZE_OF_BOOL; static final int SIZE_OF_SHORT; static final int SIZE_OF_INT; static final int SIZE_OF_LONG; static final int SIZE_OF_DOUBLE; }
@Test public void testIntFromBytes() { final byte[] bytes = {0x00, 0x10, (byte) 0xFF, (byte) 0xAB}; int read = Serialization.readInt(bytes); assertEquals(0x0010FFAB, read); }