@Override protected void overflow() { final int minCapacity = this.buf.length + 1; final int oldCapacity = this.buf.length; int newCapacity = oldCapacity << 1; if (newCapacity < minCapacity) newCapacity = minCapacity; if (newCapacity < 0) { if (minCapacity < 0) throw new OutOfMemoryError("Tried to expand buffer size beyond integer max"); newCapacity = Integer.MAX_VALUE; } final byte[] newBuf = IOUtil.getByteArray(this.buf.length << 1); System.arraycopy(this.buf, this.tail, newBuf, 0, this.buf.length - this.tail); if (this.tail > 1) System.arraycopy(this.buf, 0, newBuf, this.buf.length - this.tail, this.tail - 1); this.tail = 0; this.head = this.buf.length - 1; IOUtil.recycleByteArray(this.buf); this.buf = newBuf; }
public GrowingCircularBuffer(final int capacity) { this(IOUtil.getByteArray(capacity)); }