Here you can find the source of toLong(ByteBuffer buffer)
public static long toLong(ByteBuffer buffer)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { public static long toLong(byte[] bytes) { return toLong(ByteBuffer.wrap(bytes)); }/*from ww w .j av a2s. c o m*/ public static long toLong(ByteBuffer buffer) { return toByteBuffer(buffer, Long.BYTES).getLong(); } 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; } } }