public static long readUE7(InputStream stream) throws IOException {
        int i;
        long v = 0;
        int max = 6;
        int read = 0;
        while ((i = stream.read()) >= 0 && read++ < max) {
            v = v << 7;
            if ((i & 128) == 128) {
                // Continues
                v += (i & 127);
            } else {
                // Last value
                v += i;
                break;
            }
        }
        if (i < 0) {
            throw new IOException("Buffer underun; expected one more byte");
        }
        return v;
    }
@Test
    public void testReadUE7() throws Exception {
        byte[] data;

        data = new byte[]{0x08};
        assertEquals(8, EndianUtils.readUE7(new ByteArrayInputStream(data)));

        data = new byte[]{(byte) 0x84, 0x1e};
        assertEquals(542, EndianUtils.readUE7(new ByteArrayInputStream(data)));

        data = new byte[]{(byte) 0xac, (byte) 0xbe, 0x17};
        assertEquals(728855, EndianUtils.readUE7(new ByteArrayInputStream(data)));
    }