Here you can find the source of readVariableLength(ByteBuffer buf)
public final static int readVariableLength(ByteBuffer buf)
//package com.java2s; import java.io.InputStream; import java.nio.ByteBuffer; public class Main { public final static int readVariableLength(InputStream is) { int length = 0; int cur;//from w w w .ja v a2 s. co m try { do { cur = is.read(); length |= (cur & 0x7F); if ((cur & 0x80) != 0) length <<= 7; } while ((cur & 0x80) != 0); return length; } catch (Exception e) { return 0; } } public final static int readVariableLength(ByteBuffer buf) { int length = 0; int cur; if (buf.hasRemaining()) do { cur = buf.get(); length |= (cur & 0x7F); if ((cur & 0x80) != 0) length <<= 7; } while ((cur & 0x80) != 0 && buf.hasRemaining()); return length; } }