EndianUtils { public static long readUIntBE(InputStream stream) throws IOException, BufferUnderrunException { int ch1 = stream.read(); int ch2 = stream.read(); int ch3 = stream.read(); int ch4 = stream.read(); if ((ch1 | ch2 | ch3 | ch4) < 0) { throw new BufferUnderrunException(); } return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0)) & 0x00FFFFFFFFl; }  static short readShortLE(InputStream stream); static short readShortBE(InputStream stream); static int readUShortLE(InputStream stream); static int readUShortBE(InputStream stream); static long readUIntLE(InputStream stream); static long readUIntBE(InputStream stream); static int readIntLE(InputStream stream); static int readIntBE(InputStream stream); static long readLongLE(InputStream stream); static long readLongBE(InputStream stream); static long readUE7(InputStream stream); static short getShortLE(byte[] data); static short getShortLE(byte[] data, int offset); static int getUShortLE(byte[] data); static int getUShortLE(byte[] data, int offset); static short getShortBE(byte[] data); static short getShortBE(byte[] data, int offset); static int getUShortBE(byte[] data); static int getUShortBE(byte[] data, int offset); static int getIntLE(byte[] data); static int getIntLE(byte[] data, int offset); static int getIntBE(byte[] data); static int getIntBE(byte[] data, int offset); static long getUIntLE(byte[] data); static long getUIntLE(byte[] data, int offset); static long getUIntBE(byte[] data); static long getUIntBE(byte[] data, int offset); static long getLongLE(byte[] data, int offset); static int ubyteToInt(byte b); static short getUByte(byte[] data, int offset);  }
@Test public void testReadUIntBE() throws Exception { byte[] data = new byte[] {(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x08 }; assertEquals((long) 8, EndianUtils.readUIntBE(new ByteArrayInputStream(data))); data = new byte[] {(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xF0 }; assertEquals(4294967280L, EndianUtils.readUIntBE(new ByteArrayInputStream(data))); data = new byte[] {(byte)0xFF, (byte)0xFF, (byte)0xFF }; try { EndianUtils.readUIntLE(new ByteArrayInputStream(data)); fail("Should have thrown exception"); } catch (EndianUtils.BufferUnderrunException e) { } }