public synchronized void resize(int newSize) {
if(newSize == maxSize)
return;
LoggingEvent[] tmp = new LoggingEvent[newSize];
// we should not copy beyond the buf array
int len1 = maxSize - first;
// we should not copy beyond the tmp array
len1 = min(len1, newSize);
// er.. how much do we actually need to copy?
// We should not copy more than the actual number of elements.
len1 = min(len1, numElements);
// Copy from buf starting a first, to tmp, starting at position 0, len1 elements.
System.arraycopy(buf, first, tmp, 0, len1);
// Are there any uncopied elements and is there still space in the new array?
int len2 = 0;
if((len1 < numElements) && (len1 < newSize)) {
len2 = numElements - len1;
len2 = min(len2, newSize - len1);
System.arraycopy(buf, 0, tmp, len1, len2);
}
this.buf = tmp;
this.maxSize = newSize;
this.first=0;
this.numElements = len1+len2;
this.next = this.numElements;
if(this.next == this.maxSize) // this should never happen, but again, it just might.
this.next = 0;
}
Resize the buffer to a new size. If the new size is smaller than
the old size events might be lost. |