Java ByteBuffer to Int readVarInt(ByteBuffer buffer)

Here you can find the source of readVarInt(ByteBuffer buffer)

Description

read Var Int

License

Open Source License

Declaration

public static int readVarInt(ByteBuffer buffer) throws IOException 

Method Source Code


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

import java.io.IOException;

import java.nio.ByteBuffer;

public class Main {
    public static int readVarInt(ByteBuffer buffer) throws IOException {
        int i = 0;
        int j = 0;

        while (true) {
            int b0 = buffer.get();
            i |= (b0 & 127) << j++ * 7;

            if (j > 5) {
                throw new IOException("VarInt too big");
            }/*from www  .  j  a  va 2 s. c  om*/

            if ((b0 & 128) != 128) {
                break;
            }
        }

        return i;
    }
}

Related

  1. readUnsignedTriByte(ByteBuffer buffer)
  2. readUnsignedVarint(ByteBuffer buffer)
  3. readVarInt(ByteBuffer buff)
  4. readVarInt(ByteBuffer buff)
  5. readVarint(ByteBuffer buffer)
  6. readVarInt(ByteBuffer stream)
  7. readVarIntRest(ByteBuffer buff, int b)
  8. toInt(ByteBuffer buffer)
  9. toInt(ByteBuffer buffer)