ExtendedDataOutputStream extends DataOutputStream { public void writeVInt(int i) throws IOException { if ((i & ~0x7F) != 0) { writeByte((byte) ((i & 0x7F) | 0x80)); i >>>= 7; if ((i & ~0x7F) != 0) { writeByte((byte) ((i & 0x7F) | 0x80)); i >>>= 7; if ((i & ~0x7F) != 0) { writeByte((byte) ((i & 0x7F) | 0x80)); i >>>= 7; if ((i & ~0x7F) != 0) { writeByte((byte) ((i & 0x7F) | 0x80)); i >>>= 7; } } } } writeByte((byte) i); } ExtendedDataOutputStream(OutputStream out); void writeVInt(int i); void writeVLong(long i); void writeZInt(int i); void writeZLong(long l); void writeArray(Bytes data); void writeNullArray(); void writeArray(byte[] data); void writeArray(byte[] data, int offset, int len); static final ExtendedDataOutputStream NULL; }
@Test public void testWriteVInt() throws IOException { checkAndCompareVInt(new byte[]{0}, 0); checkAndCompareVInt(new byte[]{1}, 1); checkAndCompareVInt(new byte[]{-1, -1, -1, -1, 15}, -1); checkAndCompareVInt(new byte[]{-128, -128, -128, -128, 8}, Integer.MIN_VALUE); checkAndCompareVInt(new byte[]{-1, -1, -1, -1, 7}, Integer.MAX_VALUE); }