ByteUtils { public static int toInteger(byte[] bytes) { return toInteger(bytes, true); }  static byte[] clone(@Nullable byte[] input); static byte[] concatenate(byte[] x, byte[] y); static byte[] concatenate(byte x, byte[] y); static byte[] concatenate(byte[] x, byte y); static byte[] concatenate(byte x, byte y); static byte[] cutLeadingNullBytes(byte[] input); static byte[] cutLeadingNullByte(byte[] input); static byte[] copy(byte[] input, int offset, int length); static boolean compare(byte[] x, byte[] y); static boolean compare(byte x, byte[] y); static boolean compare(byte[] x, byte y); static boolean compare(byte x, byte y); static boolean isPrefix(byte[] prefix, byte[] data); static boolean isPrefix(byte prefix, byte[] data); static byte[] reverse(byte[] in); static String toHexString(@Nullable byte[] bytes); static String toHexString(@Nullable byte[] bytes, boolean formatted); static String toHexString(@Nullable byte[] bytes, boolean formatted, boolean addLinebreak); static String toFileSafeBase64String(@Nullable byte[] bytes); static String toWebSafeBase64String(@Nullable byte[] bytes); static String toFileSafeBase64String(@Nullable byte[] bytes, boolean withPadding); static short toShort(byte[] bytes); static short toShort(byte[] bytes, boolean bigEndian); static int toInteger(byte[] bytes); static int toInteger(byte[] bytes, boolean bigEndian); static long toLong(byte[] bytes); static long toLong(byte[] bytes, boolean bigEndian); static boolean isBitSet(int position, byte[] array); static void setBit(int position, byte[] array);  }
@Test public void testToInteger() { byte[] input = new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }; int s = ByteUtils.toInteger(input); assertEquals(-1, s); input = new byte[] { (byte) 0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }; s = ByteUtils.toInteger(input); assertEquals(Integer.MAX_VALUE, s); input = new byte[] { (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00 }; s = ByteUtils.toInteger(input); assertEquals(Integer.MIN_VALUE, s); input = new byte[5]; try { ByteUtils.toInteger(input); fail("An IllegalArgumentException should have been thrown."); } catch (IllegalArgumentException e) { } input = new byte[0]; try { ByteUtils.toInteger(input); fail("An IllegalArgumentException should have been thrown."); } catch (IllegalArgumentException e) { } }