public static void writeVLong(ByteBuffer out, long i) {
        if (i >= -112 && i <= 127) {
            out.put((byte) i);
            return;
        }

        int len = -112;
        if (i < 0) {
            i ^= -1L; // take one's complement
            len = -120;
        }

        long tmp = i;
        while (tmp != 0) {
            tmp = tmp >> 8;
            len--;
        }

        out.put((byte) len);

        len = (len < -120)
                ? -(len + 120)
                : -(len + 112);

        for (int idx = len; idx != 0; idx--) {
            int shiftbits = (idx - 1) * 8;
            long mask = 0xFFL << shiftbits;
            out.put((byte) ((i & mask) >> shiftbits));
        }
    }
Similar to {@link WritableUtils#writeVLong(java.io.DataOutput, long)}, but writes to a
{@link ByteBuffer}.
stroom-bytebuffer/src/main/java/stroom/bytebuffer/hbase/ByteBufferUtils.java