ByteArrayUtil { public static long getLong(byte[] array, int offset) { return ((long) (array[offset] & 0xff) << 56) | ((long) (array[offset + 1] & 0xff) << 48) | ((long) (array[offset + 2] & 0xff) << 40) | ((long) (array[offset + 3] & 0xff) << 32) | ((long) (array[offset + 4] & 0xff) << 24) | ((long) (array[offset + 5] & 0xff) << 16) | ((long) (array[offset + 6] & 0xff) << 8) | ((long) (array[offset + 7] & 0xff)); }  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 testGetLong() { assertEquals(0L, ByteArrayUtil.getLong(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }, 0)); assertEquals(1L, ByteArrayUtil.getLong(new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 }, 0)); assertEquals(1L << 56, ByteArrayUtil.getLong(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0 }, 0)); assertEquals(0L, ByteArrayUtil.getLong(new byte[] { 127, 0, 0, 0, 0, 0, 0, 0, 0, 127 }, 1)); thrown.expect(ArrayIndexOutOfBoundsException.class); ByteArrayUtil.getLong(new byte[] { 1 }, 0); }