ByteBuffer (int requiredSize) { int size = roundUpInt(requiredSize, MIN_SIZE); Map.Entry<Integer, ByteBuffer> entry; do { entry = pool.ceilingEntry(size); if (entry == null) { break; } } while (!pool.remove(entry.getKey(), entry.getValue())); ByteBuffer result; if (entry == null) { result = ByteBuffer.allocateDirect(size); } else { count.decrementAndGet(); result = entry.getValue(); } result.limit(requiredSize); return result; }