Compresses the input data and fills the specified buffer with compressed data. Returns actual number of bytes of data compressed.
Compression flush mode is one of the following three modes:
-
NO_FLUSH
: allows the deflater to decide how much data to accumulate, before producing output, in order to achieve the best compression (should be used in normal use scenario). A return value of 0 in this flush mode indicates that needsInput()
should be called in order to determine if more input data is required.
-
SYNC_FLUSH
: all pending output in the deflater is flushed, to the specified output buffer, so that an inflater that works on compressed data can get all input data available so far (In particular the needsInput()
returns true
after this invocation if enough output space is provided). Flushing with SYNC_FLUSH
may degrade compression for some compression algorithms and so it should be used only when necessary.
-
FULL_FLUSH
: all pending output is flushed out as with SYNC_FLUSH
. The compression state is reset so that the inflater that works on the compressed output data can restart from this point if previous compressed data has been damaged or if random access is desired. Using FULL_FLUSH
too often can seriously degrade compression.
In the case of FULL_FLUSH
or SYNC_FLUSH
, if the return value is equal to the remaining space of the buffer, this method should be invoked again with the same flush
parameter and more output space. Make sure that the buffer has at least 6 bytes of remaining space to avoid the flush marker (5 bytes) being repeatedly output to the output buffer every time this method is invoked.
On success, the position of the given output
byte buffer will be advanced by as many bytes as were produced by the operation, which is equal to the number returned by this method.
If the setInput(ByteBuffer)
method was called to provide a buffer for input, the input buffer's position will be advanced by the number of bytes consumed by this operation.