Here you can find the source of toInt(ByteBuffer buffer)
public static int toInt(ByteBuffer buffer)
//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; } } }