Data { public int getUnsignedInt() { if (pointer + 4 > data.length) { throw new IndexOutOfBoundsException("Not enough data to compute length"); } int ret = ((data[pointer + 0] & 0xFF) << 24) | ((data[pointer + 1] & 0xFF) << 16) | ((data[pointer + 2] & 0xFF) << 8) | ((data[pointer + 3] & 0xFF)); pointer += 4; return ret; } Data(byte[] data); int getUnsignedInt(); int getByte(); char getChar(); long getLongInteger(); String getString(); byte[] getBuffer(); String getPointer(); long getTime(); Hashtable getHashtable(); Hdata getHdata(); Info getInfo(); Infolist getInfolist(); Array getArray(); RelayObject getObject(); byte[] getByteArray(); boolean empty();  }
@Test public void testGetInteger() { int testCases[] = new int[] {260, 0, -99999999, 99999999, 1234567890, -0, Integer.MAX_VALUE, Integer.MIN_VALUE}; for (int o: testCases) { ByteBuffer bb = ByteBuffer.allocate(6); bb.order(ByteOrder.BIG_ENDIAN); bb.putInt(o); Data d = new Data(bb.array()); int i = d.getUnsignedInt(); assertEquals(o, i); } }
@Test(expected = IndexOutOfBoundsException.class) public void testGetIntegerException() { Data d = new Data(new byte[]{3}); d.getUnsignedInt(); }