private void ensureFree(int need) {
        if (buf.length < used + need) {
            int newSize = Math.max(buf.length, 8);
            while (newSize < used + need) {
                newSize *= 2;
            }
            Object[] newBuf = new Object[newSize];
            for (int i = 0; i < used; i++) {
                newBuf[i] = buf[readPos++];
                if (readPos == buf.length) {
                    readPos = 0;
                }
            }
            buf = newBuf;
            readPos = 0;
            writePos = used; // this cannot wrap
        }
    }
Ensure the queue has room for the specified number of
additional elements.

@param need space needed on queue
jrt/src/com/yahoo/jrt/Queue.java