LongPacker { static public int packLong(DataOutput os, long value) throws IOException { if (value < 0) { throw new IllegalArgumentException("negative value: v=" + value); } int i = 1; while ((value & ~0x7FL) != 0) { os.write((((int) value & 0x7F) | 0x80)); value >>>= 7; i++; } os.write((byte) value); return i; } private  LongPacker(); static int packLong(DataOutput os, long value); static int packLong(byte[] ba, long value); static long unpackLong(DataInput is); static long unpackLong(byte[] ba); static long unpackLong(byte[] ba, int index); static int packInt(DataOutput os, int value); static int unpackInt(DataInput is); static int unpackInt(ByteBuffer bb);  }
@Test public void testPackLong() throws IOException { DataInputOutput dio = new DataInputOutput(); LongPacker.packLong(dio.reset(), 42l); Assert.assertEquals(LongPacker.unpackLong(dio.reset(dio.toByteArray())), 42); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testPackLongNeg() throws IOException { DataInputOutput dio = new DataInputOutput(); LongPacker.packLong(dio.reset(), -42l); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testPackLongBytesNeg() throws IOException { LongPacker.packLong(new byte[15], -42l); }