Java ByteBuffer Set getSignedInt(ByteBuffer buffer, int offset)

Here you can find the source of getSignedInt(ByteBuffer buffer, int offset)

Description

Reads a big-endian signed integer from the buffer and advances position.

License

Open Source License

Declaration

static int getSignedInt(ByteBuffer buffer, int offset) 

Method Source Code

//package com.java2s;
/*//from   w  ww .  j  av  a2s.c  om
 * 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 signed integer from the buffer and advances position.
     */
    static int getSignedInt(ByteBuffer buffer, int offset) {
        return (buffer.get(offset) & 0xFF) << 24
                | (buffer.get(offset + 1) & 0xFF) << 16
                | (buffer.get(offset + 2) & 0xFF) << 8
                | buffer.get(offset + 3) & 0xFF;
    }

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

Related

  1. from(ByteBuffer buffer, int offset)
  2. fromListToSetByteArray(List list)
  3. get(ByteBuffer srcBuffer, byte[] dstBytes, int dstOffset, int length)
  4. getCharsetFromDocument(ByteBuffer bb)
  5. getEquals(ByteBuffer buf, String s, String charsetName)
  6. hash_murmur3_128(ByteBuffer buf, int offset, int size, int i, byte[] result)
  7. isFree(int frameIx, int offset, ByteBuffer[] frames)
  8. macAddressToString(ByteBuffer packet, int offset, boolean needHyphen)
  9. memset(ByteBuffer dstBuffer, int dstByteOffset, byte value, int length)