private ByteBuffer ensureBuffer ( int size , ByteBuffer buffer , WritableByteChannel output ) throws IOException { if ( buffer . remaining ( ) >= size ) { return buffer ; } flushBuffer ( buffer , output ) ; if ( buffer . remaining ( ) >= size ) { return buffer ; } // Aggressively grow the buffer return ByteBuffer . allocateDirect ( Math . max ( buffer . capacity ( ) << 1 , buffer . capacity ( ) + size ) ) ; }
Ensure the buffer is large enough .