Java ByteBuffer Read readSize(ByteBuffer buf)

Here you can find the source of readSize(ByteBuffer buf)

Description

Read size from ByteBuffer

License

Open Source License

Parameter

Parameter Description
buf Buffer

Return

Size

Declaration

public static int readSize(ByteBuffer buf) 

Method Source Code


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

import java.nio.ByteBuffer;

public class Main {
    /**/*from  w w w. j av  a2  s . com*/
     * Read size from ByteBuffer
     * @param buf       Buffer
     * @return          Size
     */
    public static int readSize(ByteBuffer buf) {
        int s = 0;
        for (int count = 0; count < 4; count++) {
            byte b = (byte) (buf.get() & 0xff);
            s <<= 7;
            s |= b & 0x7f;
            if (0 == (b & 0x80)) {
                break;
            }
        }
        return s;
    }
}

Related

  1. readShortLE(ByteBuffer buf, int i)
  2. readShortLength(ByteBuffer bb)
  3. readShorts(final ByteBuffer bb, final int length)
  4. readShortString(ByteBuffer buffer)
  5. readSignedVarint(ByteBuffer buffer)
  6. readSize(ByteBuffer buffer)
  7. readSmart(ByteBuffer buffer)
  8. readToBytes(ByteBuffer byteBuffer)
  9. readTs(ByteBuffer is)