ByteBuffer (int expectedRecordSizeHint) { ByteBuffer temp = threadLocalBuffer.get(); if (temp != null && temp.capacity() >= expectedRecordSizeHint) { threadLocalBuffer.set(null); return temp.position(0) .limit(0); } else { int defaultCapacity = allocationStrategy.defaultCapacity(); int capacity = Math.max(defaultCapacity, expectedRecordSizeHint); ByteBuffer buffer = ByteBuffer.allocate(capacity); buffer.order(byteOrder); return buffer; } }