Java ByteBuffer Put putVInt(ByteBuffer b, int i)

Here you can find the source of putVInt(ByteBuffer b, int i)

Description

put V Int

License

Open Source License

Declaration

public static final int putVInt(ByteBuffer b, int i) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    public static final int putVInt(ByteBuffer b, int i) {
        int j = 0;
        while ((i & ~0x7F) != 0) {
            b.put((byte) ((i & 0x7f) | 0x80));
            i >>>= 7;/*from w w w . j  av  a2 s.  co  m*/
            j++;
        }
        b.put((byte) i);
        return ++j;
    }

    public static final int putVInt(byte[] b, int index, int i) {
        while ((i & ~0x7F) != 0) {
            b[index++] = (byte) ((i & 0x7f) | 0x80);
            i >>>= 7;
        }
        b[index++] = (byte) i;
        return index;
    }
}

Related

  1. putUnsignedInt(ByteBuffer buffer, long value)
  2. putUnsignedInt(final ByteBuffer dst, final long value)
  3. putUnsignedShort(ByteBuffer bytes, int value)
  4. putUUID(ByteBuffer bytes, UUID uuid)
  5. putVarint(ByteBuffer buffer, long number, int byteSize)
  6. putWhatFits(ByteBuffer dest, ByteBuffer src)
  7. putWithChecksum(ByteBuffer buffer, int value, Adler32 checksum)
  8. read(InputStream is, ByteBuffer buf, int bytes)
  9. readAsByteBuffer(final InputStream source)