/** * Reads the given number of bytes from the given supplier as a little endian long. * * <p>Typically used by our InputStreams that need to count the * bytes read as well.</p> * * @param supplier the supplier for bytes * @param length the number of bytes representing the value * @return the number read * @throws IllegalArgumentException if len is bigger than eight * @throws IOException if the supplier fails or doesn't supply the * given number of bytes anymore */ public static long fromLittleEndian(ByteSupplier supplier, final int length) throws IOException { checkReadLength(length); long l = 0; for (int i = 0; i < length; i++) { long b = supplier.getAsByte(); if (b == -1) { throw new IOException("premature end of data"); } l |= (b << (i * 8)); } return l; }
/** * Reads the given number of bytes from the given supplier as a little endian long. * * <p>Typically used by our InputStreams that need to count the * bytes read as well.</p> * * @param supplier the supplier for bytes * @param length the number of bytes representing the value * @return the number read * @throws IllegalArgumentException if len is bigger than eight * @throws IOException if the supplier fails or doesn't supply the * given number of bytes anymore */ public static long fromLittleEndian(ByteSupplier supplier, final int length) throws IOException { checkReadLength(length); long l = 0; for (int i = 0; i < length; i++) { long b = supplier.getAsByte(); if (b == -1) { throw new IOException("premature end of data"); } l |= (b << (i * 8)); } return l; }