Java ByteBuffer to Int toInt(ByteBuffer buffer)

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

Description

to Int

License

Open Source License

Declaration

public static int toInt(ByteBuffer buffer) 

Method Source Code

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

import java.nio.ByteBuffer;

public class Main {
    public static int toInt(byte[] bytes) {
        return toInt(ByteBuffer.wrap(bytes));
    }//from  w w w .j a  v a  2 s .c  o m

    public static int toInt(ByteBuffer buffer) {
        return toByteBuffer(buffer, Integer.BYTES).getInt();
    }

    protected static ByteBuffer toByteBuffer(ByteBuffer buffer, int length) {
        if (length > buffer.remaining()) {
            return (ByteBuffer) ((ByteBuffer) ByteBuffer.allocate(length).position(length - buffer.remaining()))
                    .put(buffer.array()).rewind();
        } else {
            return buffer;
        }
    }
}

Related

  1. readVarInt(ByteBuffer buff)
  2. readVarint(ByteBuffer buffer)
  3. readVarInt(ByteBuffer buffer)
  4. readVarInt(ByteBuffer stream)
  5. readVarIntRest(ByteBuffer buff, int b)
  6. toInt(ByteBuffer buffer)
  7. toInt(ByteBuffer bytes)
  8. toInt(ByteBuffer value)
  9. toInt16BE(ByteBuffer buf, int[] out)