public static void putCompressedPositiveNumber(int n, ByteBuffer buf) {
        if (n < 0) {
            throw new IllegalArgumentException("Number '" + n + "' must be positive");
        }
        if (n < (0x1 << 6)) {
            buf.put((byte)n);
        } else if (n < (0x1 << 14)) {
            n = n | 0x8000;
            buf.putShort((short)n);
        } else if ( n < (0x1 << 30)) {
            n = n | 0xc0000000;
            buf.putInt(n);
        } else {
            throw new IllegalArgumentException("Number '" + n + "' too big, must extend encoding");
        }
    }
Utility for bytewise compressing of integers into a ByteBuffer.

@author baldersheim
vespajlib/src/main/java/com/yahoo/compress/IntegerCompressor.java