Here you can find the source of read(ByteBuffer bb, int elementWidth)
public static long read(ByteBuffer bb, int elementWidth)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; import java.nio.ByteOrder; public class Main { public static long read(ByteBuffer bb, int elementWidth) { final long value = readBE(bb, elementWidth); if (bb.order() == ByteOrder.BIG_ENDIAN) { return value; }//from w ww. ja va 2s. c o m return swap(elementWidth, value); } private static long readBE(ByteBuffer bb, int elementWidth) { final int p = bb.position(); long value = 0; for (int j = 0; j < elementWidth; j++) { value = (value << 8) | (bb.get(p + j) & 0xff); } bb.position(p + elementWidth); return value; } private static long swap(int elementWidth, long value) { return Long.reverseBytes(value) >>> (8 * (8 - elementWidth)); } }