So I have a input stream from which I read a smaller fixed-size buffer which I’m trying to Deflate inside a Runnable class.
randomClass implements Runnable {
public void run() {
...
byte[] output = new Byte[FIXED];
Deflater deflater = new Deflater();
deflater.setInput(uncompressed);
deflater.setLevel(Deflater.DEFLATED);
int length = deflater.deflate(output);
...
}
}
The issue I’m running into is that length is always returning 0 which means I need more input according to the doc? However, I’ve checked that the uncompressed is not null. How can I get the bytes out of the output?
Also I believe I should be calling deflater.finish() only at the last block. Is this correct?
I think
compresser.finish();should be called right afterdeflater.setInput(uncompressed);. Then proceed with the next steps, it should be fine.Same is mentioned in the documentation as below:
Also, please set the level at the time of initialization e.g.
Hope this helps.