private void deflateData ( boolean force ) throws IOException { //we don't need to flush here, as this should have been called already by the time we get to //this point boolean nextCreated = false ; try ( PooledByteBuffer arrayPooled = this . exchange . getConnection ( ) . getByteBufferPool ( ) . getArrayBackedPool ( ) . allocate ( ) ) { PooledByteBuffer pooled = this . currentBuffer ; final ByteBuffer outputBuffer = pooled . getBuffer ( ) ; final boolean shutdown = anyAreSet ( state , SHUTDOWN ) ; ByteBuffer buf = arrayPooled . getBuffer ( ) ; while ( force || ! deflater . needsInput ( ) || ( shutdown && ! deflater . finished ( ) ) ) { int count = deflater . deflate ( buf . array ( ) , buf . arrayOffset ( ) , buf . remaining ( ) , force ? Deflater . SYNC_FLUSH : Deflater . NO_FLUSH ) ; Connectors . updateResponseBytesSent ( exchange , count ) ; if ( count != 0 ) { int remaining = outputBuffer . remaining ( ) ; if ( remaining > count ) { outputBuffer . put ( buf . array ( ) , buf . arrayOffset ( ) , count ) ; } else { if ( remaining == count ) { outputBuffer . put ( buf . array ( ) , buf . arrayOffset ( ) , count ) ; } else { outputBuffer . put ( buf . array ( ) , buf . arrayOffset ( ) , remaining ) ; additionalBuffer = ByteBuffer . allocate ( count - remaining ) ; additionalBuffer . put ( buf . array ( ) , buf . arrayOffset ( ) + remaining , count - remaining ) ; additionalBuffer . flip ( ) ; } outputBuffer . flip ( ) ; this . state |= FLUSHING_BUFFER ; if ( next == null ) { nextCreated = true ; this . next = createNextChannel ( ) ; } if ( ! performFlushIfRequired ( ) ) { return ; } } } else { force = false ; } } } finally { if ( nextCreated ) { if ( anyAreSet ( state , WRITES_RESUMED ) ) { next . resumeWrites ( ) ; } } } }
Runs the current data through the deflater . As much as possible this will be buffered in the current output stream .