Here you can find the source of readVarInt(ByteBuffer buff)
public static int readVarInt(ByteBuffer buff)
//package com.java2s; //License from project: LGPL import java.nio.ByteBuffer; public class Main { /**/*from ww w. jav a 2s . c o m*/ * Reads a VarInt. * * @return the int value */ public static int readVarInt(ByteBuffer buff) { int shift = 0, i = 0; while (true) { byte b = (byte) buff.get(); i |= (b & 0x7F) << shift;// Remove sign bit and shift to get the next 7 bits shift += 7; if (b >= 0) {// VarInt byte prefix is 0, it means that we just decoded the last 7 bits, therefore we've // finished. return i; } } } }