### Question:
EndianUtils { public static long readSwappedUnsignedInteger(final byte[] data, final int offset) { final long low = ( ( ( data[ offset + 0 ] & 0xff ) << 0 ) + ( ( data[ offset + 1 ] & 0xff ) << 8 ) + ( ( data[ offset + 2 ] & 0xff ) << 16 ) ); final long high = data[ offset + 3 ] & 0xff; return (high << 24) + (0xffffffffL & low); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input);  }### Answer:
@Test public void testReadSwappedUnsignedInteger() throws IOException { final byte[] bytes = new byte[] { 0x04, 0x03, 0x02, 0x01 }; assertEquals( 0x0000000001020304L, EndianUtils.readSwappedUnsignedInteger( bytes, 0 ) ); final ByteArrayInputStream input = new ByteArrayInputStream(bytes); assertEquals( 0x0000000001020304L, EndianUtils.readSwappedUnsignedInteger( input ) ); }
@Test public void testUnsignedOverrun() throws Exception { final byte[] target = new byte[] { 0, 0, 0, (byte)0x80 }; final long expected = 0x80000000L; long actual = EndianUtils.readSwappedUnsignedInteger(target, 0); assertEquals("readSwappedUnsignedInteger(byte[], int) was incorrect", expected, actual); final ByteArrayInputStream in = new ByteArrayInputStream(target); actual = EndianUtils.readSwappedUnsignedInteger(in); assertEquals("readSwappedUnsignedInteger(InputStream) was incorrect", expected, actual); }