예제 #1
0
 /**
  * @throws IllegalArgumentException if variable-length value does not terminate after 5 bytes have
  *     been read
  * @throws IOException if {@link DataInput} throws {@link IOException}
  * @see #readUnsignedVarLong(DataInput)
  */
 public static int readUnsignedVarInt(DataInput in) throws IOException {
   int value = 0;
   int i = 0;
   int b;
   while (((b = in.readByte()) & 0x80) != 0) {
     value |= (b & 0x7F) << i;
     i += 7;
     Assert.isTrue(i <= 35, "Variable length quantity is too long");
   }
   return value | (b << i);
 }
예제 #2
0
 /**
  * @param in to read bytes from
  * @return decode value
  * @throws IOException if {@link DataInput} throws {@link IOException}
  * @throws IllegalArgumentException if variable-length value does not terminate after 9 bytes have
  *     been read
  * @see #writeUnsignedVarLong(long, DataOutput)
  */
 public static long readUnsignedVarLong(DataInput in) throws IOException {
   long value = 0L;
   int i = 0;
   long b;
   while (((b = in.readByte()) & 0x80L) != 0) {
     value |= (b & 0x7F) << i;
     i += 7;
     Assert.isTrue(i <= 63, "Variable length quantity is too long");
   }
   return value | (b << i);
 }