Here you can find the source of setupByteBuffer(ByteBuffer preBuffer, byte[] array)
public static ByteBuffer setupByteBuffer(ByteBuffer preBuffer, byte[] array)
//package com.java2s; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class Main { public static ByteBuffer setupByteBuffer(ByteBuffer preBuffer, byte[] array) { if (preBuffer == null || preBuffer.capacity() < array.length) { preBuffer = createByteBuffer(array.length * 2); } else {/*ww w .j a va 2 s . c o m*/ preBuffer.clear(); } preBuffer.put(array); preBuffer.position(0); return preBuffer; } public static ByteBuffer createByteBuffer(int count) { ByteBuffer data = ByteBuffer.allocateDirect(count * 4); data.order(ByteOrder.nativeOrder()); return data; } }