protected final void expand ( int needed ) { int ocapacity = _buffer . capacity ( ) ; int ncapacity = _buffer . position ( ) + needed ; if ( ncapacity > ocapacity ) { // increase the buffer size in large increments ncapacity = Math . max ( ocapacity << 1 , ncapacity ) ; ByteBuffer newbuf = ByteBuffer . allocate ( ncapacity ) ; newbuf . put ( ( ByteBuffer ) _buffer . flip ( ) ) ; _buffer = newbuf ; } }
Expands our buffer to accomodate the specified capacity .