protected List < WsByteBuffer > compress ( List < WsByteBuffer > list , WsByteBuffer buffer ) { if ( null == buffer ) { return null ; } int dataSize = buffer . remaining ( ) ; if ( 0 == dataSize ) { return list ; } byte [ ] input = null ; int initOffset = 0 ; if ( buffer . hasArray ( ) ) { input = buffer . array ( ) ; initOffset = buffer . arrayOffset ( ) + buffer . position ( ) ; buffer . position ( buffer . limit ( ) ) ; } else { input = new byte [ dataSize ] ; buffer . get ( input ) ; } this . deflater . setInput ( input , initOffset , dataSize ) ; // keep compressing data until we use up the input amount int offset = 0 ; while ( ! this . deflater . needsInput ( ) ) { int len = this . deflater . deflate ( this . buf , offset , this . buf . length - offset ) ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "Compressed amount=" + len + " read=" + this . deflater . getBytesRead ( ) + " written=" + this . deflater . getBytesWritten ( ) ) ; } if ( 0 == len ) { break ; // out of while } offset += len ; if ( offset == this . buf . length ) { list . add ( makeBuffer ( offset ) ) ; offset = 0 ; } } // if we generated output, put it into a buffer on the list if ( 0 < offset ) { list . add ( makeBuffer ( offset ) ) ; } return list ; }
Compress the given input buffer onto the output list .