Java ByteBuffer Get getVInt(ByteBuffer bf, int index)

Here you can find the source of getVInt(ByteBuffer bf, int index)

Description

get V Int

License

Open Source License

Declaration

public static final int getVInt(ByteBuffer bf, int index) 

Method Source Code

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

import java.nio.ByteBuffer;

public class Main {
    public static final int getVInt(ByteBuffer bf, int index) {
        byte b = bf.get(index++);
        int i = b & 0x7F;
        for (int shift = 7; (b & 0x80) != 0; shift += 7) {
            b = bf.get(index++);/*from   w  w  w .j a  v a  2  s .c  o  m*/
            i |= (b & 0x7F) << shift;
        }
        return i;
    }

    public static final int getVInt(ByteBuffer bf) {
        byte b = bf.get();
        int i = b & 0x7F;
        for (int shift = 7; (b & 0x80) != 0; shift += 7) {
            b = bf.get();
            i |= (b & 0x7F) << shift;
        }
        return i;
    }

    public static final int getVInt(byte[] b, int[] index) {
        int i = b[index[0]] & 0x7F;
        for (int shift = 7; (b[index[0]++] & 0x80) != 0; shift += 7)
            i |= (b[index[0]] & 0x7F) << shift;
        return i;
    }

    public static final int getVInt(byte[] b) {
        int i = b[0] & 0x7F;
        int j = 1;
        for (int shift = 7; j < b.length; shift += 7)
            i |= (b[j++] & 0x7F) << shift;
        return i;
    }

    public static final byte[] getVInt(int i) {
        byte[] tmp = new byte[5];
        int j = 0;
        while ((i & ~0x7F) != 0) {
            tmp[j++] = (byte) ((i & 0x7f) | 0x80);
            i >>>= 7;
        }
        tmp[j++] = (byte) i;
        byte[] ret = new byte[j];
        System.arraycopy(tmp, 0, ret, 0, j);
        return ret;
    }
}

Related

  1. getUleb128(ByteBuffer buffer)
  2. getUsedBytes(ByteBuffer bb)
  3. getUTF8FromByteBuffer(ByteBuffer bb)
  4. getUUID(ByteBuffer bytes)
  5. getVariance(ByteBuffer simulationResults)
  6. getWithShortLength(ByteBuffer bb)
  7. getZeroTerminatedStringBytes(ByteBuffer dataBuffer)
  8. getZipEocdCentralDirectorySizeBytes(ByteBuffer zipEndOfCentralDirectory)
  9. insertByteArray(byte[] source, ByteBuffer target)