nl_tokens: Fills specified buffer with compressed data . Returns actual number of bytes of compressed data . A return value of 0 indicates that needsInput () should be called in order to determine if more input data is required .
pl_tokens: @ Override public synchronized int compress ( byte [ ] buffer , int off , int len ) throws IOException { SnappyUtil . validateBuffer ( buffer , off , len ) ; if ( needsInput ( ) ) { // No buffered output bytes and no input to consume, need more input return 0 ; } if ( ! outputBuffer . hasRemaining ( ) ) { // There is uncompressed input, compress it now int maxOutputSize = Snappy . maxCompressedLength ( inputBuffer . position ( ) ) ; if ( maxOutputSize > outputBuffer . capacity ( ) ) { ByteBuffer oldBuffer = outputBuffer ; outputBuffer = ByteBuffer . allocateDirect ( maxOutputSize ) ; CleanUtil . clean ( oldBuffer ) ; } // Reset the previous outputBuffer outputBuffer . clear ( ) ; inputBuffer . limit ( inputBuffer . position ( ) ) ; inputBuffer . position ( 0 ) ; int size = Snappy . compress ( inputBuffer , outputBuffer ) ; outputBuffer . limit ( size ) ; inputBuffer . limit ( 0 ) ; inputBuffer . rewind ( ) ; } // Return compressed output up to 'len' int numBytes = Math . <mask> ( len , outputBuffer . remaining ( ) ) ; outputBuffer . get ( buffer , off , numBytes ) ; bytesWritten += numBytes ; return numBytes ; }