LittleEndianUtils { public static long readUnsigned4Le(@NonNull ByteBuffer bytes) throws IOException { Preconditions.checkNotNull(bytes, "bytes == null"); if (bytes.remaining() < 4) { throw new EOFException("Not enough data: 4 bytes expected, " + bytes.remaining() + " available."); } byte b0 = bytes.get(); byte b1 = bytes.get(); byte b2 = bytes.get(); byte b3 = bytes.get(); long r = (b0 & 0xff) | ((b1 & 0xff) << 8) | ((b2 & 0xff) << 16) | ((b3 & 0xffL) << 24); Verify.verify(r >= 0); Verify.verify(r <= 0x00000000ffffffffL); return r; } private  LittleEndianUtils(); static long readUnsigned4Le(@NonNull ByteBuffer bytes); static int readUnsigned2Le(@NonNull ByteBuffer bytes); static void writeUnsigned4Le(@NonNull ByteBuffer output, long value); static void writeUnsigned2Le(@NonNull ByteBuffer output, int value);  }
@Test public void read4Le() throws Exception { assertEquals(0x01020304, LittleEndianUtils.readUnsigned4Le(ByteBuffer.wrap( new byte[] { 4, 3, 2, 1 }))); assertEquals(0xfedcba98L, LittleEndianUtils.readUnsigned4Le(ByteBuffer.wrap( new byte[] { (byte) 0x98, (byte) 0xba, (byte) 0xdc, (byte) 0xfe }))); }