ByteArrayUtil { public static void putInt(int value, byte[] array, int offset) { array[offset] = (byte) (0xff & (value >>> 24)); array[offset + 1] = (byte) (0xff & (value >>> 16)); array[offset + 2] = (byte) (0xff & (value >>> 8)); array[offset + 3] = (byte) (0xff & value); }  static void put(byte[] source, byte[] target, int offset); static byte[] get(byte[] array, int offset); static byte[] get(byte[] array, int offset, int length); static void putInt(int value, byte[] array, int offset); static int getInt(byte[] array, int offset); static void putLong(long value, byte[] array, int offset); static long getLong(byte[] array, int offset); static int find(byte[] a, int fromIndex, int toIndex, byte key); static int find(byte[] a, int fromIndex, int toIndex, byte[] key); static boolean matchesPattern(byte[] value, byte[] mask, byte[] pattern); static boolean regionMatches(byte[] subValue, byte[] superValue, int offset); static int compareRegion(byte[] array1, int startIdx1, byte[] array2, int startIdx2, int length); static BitSet toBitSet(byte[] array); static byte[] toByteArray(BitSet bitSet); static String toHexString(byte[] array);  }
@Test public void testPutInt() { final byte[] byteArray = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; ByteArrayUtil.putInt(1, byteArray, 0); assertArrayEquals(new byte[] { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, byteArray); ByteArrayUtil.putInt(1 << 24, byteArray, 0); assertArrayEquals(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, byteArray); ByteArrayUtil.putInt(0, byteArray, 0); assertArrayEquals(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, byteArray); ByteArrayUtil.putInt(1, byteArray, 2); assertArrayEquals(new byte[] { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, byteArray); }