Java tutorial
//package com.java2s; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class Main { /** * * @param arr * @return */ public static final ByteBuffer createByteBuffer(byte[] arr) { int len = sizeofB(arr.length); ByteBuffer bb = ByteBuffer.allocateDirect(len); bb.order(ByteOrder.nativeOrder()); ByteBuffer fb = bb; fb.put(arr); fb.position(0); return fb; } /** * * @param len * @return */ public static final int sizeofB(int len) { return len; } }