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