/** * Get number of bytes that are available to be read. * <p> * Note that the number of bytes available plus * the number of bytes free may not add up to the * capacity of this buffer, as the buffer may reserve some * space for other purposes. * * @return the size in bytes of this buffer * * @since ostermillerutils 1.00.00 */ public int getAvailable(){ synchronized (this){ return available(); } }
/** * double the size of the buffer * * @since ostermillerutils 1.00.00 */ private void resize(){ byte[] newBuffer = new byte[buffer.length * 2]; int marked = marked(); int available = available(); if (markPosition <= writePosition){ // any space between the mark and // the first write needs to be saved. // In this case it is all in one piece. int length = writePosition - markPosition; System.arraycopy(buffer, markPosition, newBuffer, 0, length); } else { int length1 = buffer.length - markPosition; System.arraycopy(buffer, markPosition, newBuffer, 0, length1); int length2 = writePosition; System.arraycopy(buffer, 0, newBuffer, length1, length2); } buffer = newBuffer; markPosition = 0; readPosition = marked; writePosition = marked + available; }