public void grow ( int delta ) { if ( delta == 0 ) { return ; } int newLen = buffer . limit ( ) + delta ; if ( newLen <= buffer . capacity ( ) ) { // there is more room in the underlying reserved buffer memory buffer . limit ( newLen ) ; return ; } else { // create a new bigger buffer ByteBuffer newBuffer = buffer . isDirect ( ) ? ByteBuffer . allocateDirect ( newLen ) : ByteBuffer . allocate ( newLen ) ; buffer . rewind ( ) ; newBuffer . put ( buffer ) ; newBuffer . limit ( newLen ) ; // switch to new buffer buffer = newBuffer ; } }
Grow the internal packet buffer .