public static long readVLong(ByteBuffer buf) {
        byte firstByte = buf.get();
        int len = WritableUtils.decodeVIntSize(firstByte);
        if (len == 1) {
            return firstByte;
        } else {
            int remaining = len - 1;
            long i = 0;
            int offsetFromPos = 0;
            if (remaining >= Bytes.SIZEOF_INT) {
                // The int read has to be converted to unsigned long so the & op
                i = (buf.getInt(buf.position() + offsetFromPos) & 0x00000000ffffffffL);
                remaining -= Bytes.SIZEOF_INT;
                offsetFromPos += Bytes.SIZEOF_INT;
            }
            if (remaining >= Bytes.SIZEOF_SHORT) {
                short s = buf.getShort(buf.position() + offsetFromPos);
                i = i << 16;
                i = i | (s & 0xFFFF);
                remaining -= Bytes.SIZEOF_SHORT;
                offsetFromPos += Bytes.SIZEOF_SHORT;
            }
            for (int idx = 0; idx < remaining; idx++) {
                byte b = buf.get(buf.position() + offsetFromPos + idx);
                i = i << 8;
                i = i | (b & 0xFF);
            }
            buf.position(buf.position() + len - 1);
            return WritableUtils.isNegativeVInt(firstByte)
                    ? ~i
                    : i;
        }
    }
Similar to {@link WritableUtils#readVLong(DataInput)} but reads from a {@link ByteBuffer}.
stroom-bytebuffer/src/main/java/stroom/bytebuffer/hbase/ByteBufferUtils.java