Encode { public static void varInt(long value, OutputStream stream) throws IOException { varInt(value, stream, null); }  static void varIntList(long[] values, OutputStream stream); static void varIntList(long[] values, ByteBuffer buffer); static void varInt(long value, OutputStream stream); static void varInt(long value, ByteBuffer buffer); static byte[] varInt(long value); static void varInt(long value, OutputStream stream, AccessCounter counter); static void int8(long value, OutputStream stream); static void int8(long value, OutputStream stream, AccessCounter counter); static void int16(long value, OutputStream stream); static void int16(long value, OutputStream stream, AccessCounter counter); static void int16(long value, ByteBuffer buffer); static void int32(long value, OutputStream stream); static void int32(long value, OutputStream stream, AccessCounter counter); static void int32(long value, ByteBuffer buffer); static void int64(long value, OutputStream stream); static void int64(long value, OutputStream stream, AccessCounter counter); static void int64(long value, ByteBuffer buffer); static void varString(String value, OutputStream out); static void varString(String value, ByteBuffer buffer); static void varBytes(byte[] data, OutputStream out); static void varBytes(byte[] data, ByteBuffer buffer); static byte[] bytes(Streamable streamable); static byte[] bytes(Streamable streamable, int padding);  }
@Test public void testVarInt() throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); Encode.varInt(0, stream); checkBytes(stream, 0); stream = new ByteArrayOutputStream(); Encode.varInt(252, stream); checkBytes(stream, 252); stream = new ByteArrayOutputStream(); Encode.varInt(253, stream); checkBytes(stream, 253, 0, 253); stream = new ByteArrayOutputStream(); Encode.varInt(65535, stream); checkBytes(stream, 253, 255, 255); stream = new ByteArrayOutputStream(); Encode.varInt(65536, stream); checkBytes(stream, 254, 0, 1, 0, 0); stream = new ByteArrayOutputStream(); Encode.varInt(4294967295L, stream); checkBytes(stream, 254, 255, 255, 255, 255); stream = new ByteArrayOutputStream(); Encode.varInt(4294967296L, stream); checkBytes(stream, 255, 0, 0, 0, 1, 0, 0, 0, 0); stream = new ByteArrayOutputStream(); Encode.varInt(-1L, stream); checkBytes(stream, 255, 255, 255, 255, 255, 255, 255, 255, 255); }