Numbers { public static Long readLong(InputStream stream) throws IOException { int b = read(stream); int sign = b & 1; long value = (b >> 1) & 0x3F; for (int i = 6; (b & 0x80) != 0; i += 7) { b = read(stream); long bits = b & 0x7FL; if (i >= 62 && bits != 0 && (i > 62 || (bits == 2 ? value != 0 : bits != 1))) { throw new IllegalArgumentException("Value too long"); } value |= bits << i; } return sign == 0 ? Long.valueOf(value) : value == 0 ? null : -value; }  static byte[] serializeLong(Long value); static byte[] serializeLong(Long value, int size); static int getSerializedSize(long value); static void writeLong(Long value, OutputStream stream); static void writeLong(long value, OutputStream stream); static Long readLong(InputStream stream); static final int MAX_LONG_SIZE; static final int MAX_INT_SIZE; }
@Test public void testReadLong() throws Exception { checkRead(new byte[]{0}, 0L); checkRead(new byte[]{1}, null); checkRead(new byte[]{2}, 1L); checkRead(new byte[]{3}, -1L); }