Java ByteBuffer Get getLength(ByteBuffer buffer)

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

Description

get Length

License

Apache License

Declaration

private static int getLength(ByteBuffer buffer) 

Method Source Code

//package com.java2s;
/*//from   w ww  .  j  a v  a 2  s. com
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */

import java.math.BigInteger;

import java.nio.ByteBuffer;

public class Main {
    private static int getLength(ByteBuffer buffer) {

        int i = ((int) buffer.get()) & 0xff;

        // length 0 <= i <= 127 encoded as a single byte
        if ((i & ~0x7F) == 0) {
            return i;
        }

        // otherwise the first octet gives us the number of octets needed to read the length
        byte[] bytes = new byte[i & 0x7f];
        buffer.get(bytes);

        return new BigInteger(1, bytes).intValue();
    }
}

Related

  1. getHSBfromRGB(final ByteBuffer pixels, final float[] result, int pixelSize)
  2. getIncreasingByteBuffer(int len)
  3. getIPv4String(ByteBuffer buffer)
  4. getJagexString(ByteBuffer buf)
  5. getJceBufArray(ByteBuffer buffer)
  6. getLengthFromBuffer(ByteBuffer in)
  7. getListFromByteBuffer(ByteBuffer data, List classes)
  8. getLTriad(ByteBuffer bb)
  9. getMean(ByteBuffer simulationResults)