VByte { public static long decode(byte[] bytes, int len) { if (len > 8 || bytes.length < len) { throw new IllegalArgumentException("Buffer too long, or incorrect length"); } long val = 0L; for (int i = len - 1; i >= 0; i--) { val <<= 7; val |= bytes[i] & 0x7F; } return val; }  static boolean hasNext(byte b); static long decode(byte[] bytes, int len); static long decode(InputStream is); static long decodeFrom(byte[] b, int start); static int encodedLength(long value);  }
@Test public void test127() { assertEquals("127 not correctly decoded", 127, VByte.decode(new byte[] { (byte) 0xff }, 1)); }
@Test public void test128() { assertEquals("128 not correctly decoded", 128, VByte.decode(new byte[] { (byte) 0x00, (byte) 0x81 }, 2)); }
@Test public void test128Input() { byte b[] = new byte[] { (byte) 0x00, (byte) 0x81 }; try (ByteArrayInputStream bis = new ByteArrayInputStream(b)) { assertEquals("128 not correctly decoded", 128, VByte.decode(bis)); } catch (IOException ioe) { fail(ioe.getMessage()); } }