private ByteBuffer getBufferByMinCapacity(final int minCapacity) {
        final int originalOffset = getOffset(minCapacity);
        int offset = originalOffset;
        ByteBuffer buffer = null;
        if (isUnPooled(offset)) {
            buffer = getUnPooledBuffer(minCapacity);
        } else {
            buffer = getBufferByOffset(offset);

            if (buffer == null) {
                // No buffer at that size so try the next size up
                // We could loop and try all bigger sizes but then we risk creating a huge buffer
                // for a tiny requested capacity and having that huge buffer hang around in the pool.
                offset = getNextOffset(offset);
                if (offset == -1) {
                    // Reached max offset
                } else {
                    LOGGER.debug("Trying new offset {} (originalOffset: {})", offset, originalOffset);
                    buffer = getBufferByOffset(offset);
                }
            }

            if (buffer == null) {
                // None in the pool and not allowed to create any more pool buffers so we either
                // wait on the queue or just create an excess one that will have to be destroyed on release.
                // Creation of an excess one is a last resort due to the cost of creation/destruction
                if (byteBufferPoolConfigProvider.get().isBlockOnExhaustedPool()) {
                    try {
                        // At max pooled buffers so we just have to block and wait for another thread to release
                        final BlockingQueue<ByteBuffer> byteBufferQueue = pooledBufferQueues[originalOffset];
                        LOGGER.debug("Taking from queue, may block");
                        buffer = byteBufferQueue.take();
                    } catch (InterruptedException e) {
                        LOGGER.debug("Thread interrupted waiting for a buffer from the pool", e);
                        Thread.currentThread().interrupt();
                        throw new RuntimeException("Thread interrupted while waiting for a buffer from the pool");
                    }
                } else {
                    // Don't want to block so create a new one
                    // Excess buffers will have to be unmapped rather than returned to the pool
                    final int roundedCapacity = bufferSizes[originalOffset];
                    LOGGER.debug("Creating new buffer beyond the pool limit (capacity: {})",
                            ModelStringUtil.formatCsv(roundedCapacity));
                    buffer = ByteBuffer.allocateDirect(roundedCapacity);
                }
            }

            Objects.requireNonNull(
                    buffer,
                    "Something has gone wrong, we should not have a null buffer");

            buffer.clear();
        }
        return buffer;
    }
@param n The number to test
@return True if n is a power of ten, e.g. if n==10
stroom-bytebuffer/src/main/java/stroom/bytebuffer/ByteBufferPoolImpl4.java