Java ByteBuffer to Int getUnsignedInt(ByteBuffer buffer)

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

Description

Reads a big-endian (31-bit) integer from the buffer and advances position.

License

Open Source License

Declaration

static int getUnsignedInt(ByteBuffer buffer) 

Method Source Code

//package com.java2s;
/*/*from w  ww .  java2s  .co  m*/
 * Copyright (c) 2015 Twitter, Inc. All rights reserved.
 * Licensed under the Apache License v2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * This file is substantially based on work from the Netty project, also
 * released under the above license.
 */

import java.nio.ByteBuffer;

public class Main {
    /**
     * Reads a big-endian (31-bit) integer from the buffer at the provided offset.
     */
    static int getUnsignedInt(ByteBuffer buffer, int offset) {
        return (buffer.get(offset) & 0x7F) << 24
                | (buffer.get(offset + 1) & 0xFF) << 16
                | (buffer.get(offset + 2) & 0xFF) << 8
                | buffer.get(offset + 3) & 0xFF;
    }

    /**
     * Reads a big-endian (31-bit) integer from the buffer and advances position.
     */
    static int getUnsignedInt(ByteBuffer buffer) {
        return (buffer.get() & 0x7F) << 24 | (buffer.get() & 0xFF) << 16
                | (buffer.get() & 0xFF) << 8 | buffer.get() & 0xFF;
    }
}

Related

  1. getUnsignedByte(ByteBuffer bb)
  2. getUnsignedByte(ByteBuffer buffer)
  3. getUnsignedInt(ByteBuffer bb)
  4. getUnsignedInt(ByteBuffer buffer)
  5. getUnsignedInt(ByteBuffer buffer)
  6. getUnsignedInt16LSBMSB(ByteBuffer byteBuffer)
  7. getUnsignedLong(ByteBuffer buf)
  8. getUnsignedLong(final ByteBuffer src)
  9. getUnsignedShort(ByteBuffer bb)