Here you can find the source of getDirectByteBuffer(ByteBuffer var0, boolean var1)
private static ByteBuffer getDirectByteBuffer(ByteBuffer var0, boolean var1)
//package com.java2s; //License from project: LGPL import java.lang.ref.Reference; import java.lang.ref.SoftReference; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.HashMap; import java.util.Map; public class Main { private static final Map bufferPool = new HashMap(); private static ByteBuffer getDirectByteBuffer(ByteBuffer var0, boolean var1) { if (var0.isDirect()) { return var0; } else {//w w w . j a v a 2 s. co m ByteBuffer var2 = var1 ? getPooledBuffer(var0.capacity()) : ByteBuffer.allocateDirect(var0.capacity()); var2.order(var0.order()); var2.put(var0); var2.flip(); return var2; } } private static ByteBuffer getPooledBuffer(int var0) { Reference var1 = (Reference) bufferPool.get(Integer.valueOf(var0)); ByteBuffer var2 = var1 == null ? null : (ByteBuffer) var1.get(); if (var2 == null) { var2 = ByteBuffer.allocateDirect(var0); bufferPool.put(Integer.valueOf(var0), new SoftReference(var2)); } var2.order(ByteOrder.BIG_ENDIAN); var2.position(0); return var2; } }