needsInput() check the uncompressedDirectBuf, if it is full return false, else copy data from saved userBuf and then recheck.
A special case, that the input uncompressedDirectBuf is not all comsumed by zlib due to output buffer is not enough, should be respected. It may be the reason the original code just return false if uncompressedBufLen > 0.
After JNI compress invoked, uncompressedBufLen will be set back to the remaining input data length that not consumed by zlib. So if uncompressedBufLen > 0 after deflateBytesDirect() invoked, a flag keepUncompressedBuf is setted true to indicate no input needed and compress() should be invoked again to compress the remainling input data.