@Test public void readLong() { for (int i = 1; i < 100; ++i) { final byte[] data = new byte[i*8]; final Random random = new Random(i); for (int j = 0; j < i; ++j) { System.arraycopy(utils.toBytes(random.nextLong()), 0, data, j*8, 8); } random.setSeed(i); for (int j = 0; j < i; ++j) { Assert.assertEquals(utils.readLong(data, j), random.nextLong()); } } }
static long readLong(final byte[] bytes, final int index) { final int offset = index*Long.BYTES; if (offset + Long.BYTES > bytes.length) { throw new IndexOutOfBoundsException(format( "Not enough data to read long value (index=%d, bytes=%d).", index, bytes.length )); } return ((long)(bytes[offset ] & 255) << 56) + ((long)(bytes[offset + 1] & 255) << 48) + ((long)(bytes[offset + 2] & 255) << 40) + ((long)(bytes[offset + 3] & 255) << 32) + ((long)(bytes[offset + 4] & 255) << 24) + ((bytes[offset + 5] & 255) << 16) + ((bytes[offset + 6] & 255) << 8) + (bytes[offset + 7] & 255); }
utils { static long readLong(final byte[] bytes, final int index) { final int offset = index*Long.BYTES; if (offset + Long.BYTES > bytes.length) { throw new IndexOutOfBoundsException(format( "Not enough data to read long value (index=%d, bytes=%d).", index, bytes.length )); } return ((long)(bytes[offset ] & 255) << 56) + ((long)(bytes[offset + 1] & 255) << 48) + ((long)(bytes[offset + 2] & 255) << 40) + ((long)(bytes[offset + 3] & 255) << 32) + ((long)(bytes[offset + 4] & 255) << 24) + ((bytes[offset + 5] & 255) << 16) + ((bytes[offset + 6] & 255) << 8) + (bytes[offset + 7] & 255); } }
utils { static long readLong(final byte[] bytes, final int index) { final int offset = index*Long.BYTES; if (offset + Long.BYTES > bytes.length) { throw new IndexOutOfBoundsException(format( "Not enough data to read long value (index=%d, bytes=%d).", index, bytes.length )); } return ((long)(bytes[offset ] & 255) << 56) + ((long)(bytes[offset + 1] & 255) << 48) + ((long)(bytes[offset + 2] & 255) << 40) + ((long)(bytes[offset + 3] & 255) << 32) + ((long)(bytes[offset + 4] & 255) << 24) + ((bytes[offset + 5] & 255) << 16) + ((bytes[offset + 6] & 255) << 8) + (bytes[offset + 7] & 255); } private  utils(); }
utils { static long readLong(final byte[] bytes, final int index) { final int offset = index*Long.BYTES; if (offset + Long.BYTES > bytes.length) { throw new IndexOutOfBoundsException(format( "Not enough data to read long value (index=%d, bytes=%d).", index, bytes.length )); } return ((long)(bytes[offset ] & 255) << 56) + ((long)(bytes[offset + 1] & 255) << 48) + ((long)(bytes[offset + 2] & 255) << 40) + ((long)(bytes[offset + 3] & 255) << 32) + ((long)(bytes[offset + 4] & 255) << 24) + ((bytes[offset + 5] & 255) << 16) + ((bytes[offset + 6] & 255) << 8) + (bytes[offset + 7] & 255); } private  utils();  }
utils { static long readLong(final byte[] bytes, final int index) { final int offset = index*Long.BYTES; if (offset + Long.BYTES > bytes.length) { throw new IndexOutOfBoundsException(format( "Not enough data to read long value (index=%d, bytes=%d).", index, bytes.length )); } return ((long)(bytes[offset ] & 255) << 56) + ((long)(bytes[offset + 1] & 255) << 48) + ((long)(bytes[offset + 2] & 255) << 40) + ((long)(bytes[offset + 3] & 255) << 32) + ((long)(bytes[offset + 4] & 255) << 24) + ((bytes[offset + 5] & 255) << 16) + ((bytes[offset + 6] & 255) << 8) + (bytes[offset + 7] & 255); } private  utils();   }