private final void growIfNeeded ( int minimumDesired ) { if ( buffer . b ( ) . remaining ( ) < minimumDesired ) { // Compute the size of the new buffer int newCapacity = buffer . b ( ) . capacity ( ) ; int newRemaining = newCapacity - buffer . b ( ) . position ( ) ; while ( newRemaining < minimumDesired ) { newRemaining += newCapacity ; newCapacity *= 2 ; } // Allocate and copy BBContainer next ; if ( isDirect ) { next = DBBPool . allocateDirect ( newCapacity ) ; } else { next = DBBPool . wrapBB ( ByteBuffer . allocate ( newCapacity ) ) ; } buffer . b ( ) . flip ( ) ; next . b ( ) . put ( buffer . b ( ) ) ; assert next . b ( ) . remaining ( ) == newRemaining ; buffer . discard ( ) ; buffer = next ; if ( callback != null ) callback . onBufferGrow ( this ) ; assert ( buffer . b ( ) . order ( ) == ByteOrder . BIG_ENDIAN ) ; } }
Resizes the internal byte buffer with a simple doubling policy if needed .