/** * Resizes the ring buffer by preserving it's data. * * <p> * If the new size is not enough to keep all used data in the ring buffer, * the excess old data is discarded. */ public void resize(int newSize) { if (newSize <= 0) { throw new IllegalArgumentException(); } if (newSize < rBufUsed) { // if new buffer is too small to contain all data discard(rBufUsed - newSize); } // discard oldest data byte[] newBuf = new byte[newSize]; int newBufUsed = get(newBuf, 0, newSize); // transfer data to new buffer rBuf = newBuf; rBufSize = newSize; rBufPos = 0; rBufUsed = newBufUsed; }
/** * Resizes the ring buffer by preserving it's data. * * <p> * If the new size is not enough to keep all used data in the ring buffer, * the excess old data is discarded. */ public void resize(int newSize) { if (newSize <= 0) { throw new IllegalArgumentException(); } if (newSize < rBufUsed) { // if new buffer is too small to contain all data discard(rBufUsed - newSize); } // discard oldest data byte[] newBuf = new byte[newSize]; int newBufUsed = get(newBuf, 0, newSize); // transfer data to new buffer rBuf = newBuf; rBufSize = newSize; rBufPos = 0; rBufUsed = newBufUsed; }