I need to deflate one or more byte arrays and later inflate them back to normal size. I've looked over the example given in the api docs, and found some other examples.
After looking these examples over, I have two questions which may be unrelated, but they seem connected as I'm trying to understand this.
In the API documentation example, the output buffer for both the Inflater and Deflater is set at 1024 bytes. The example data is only a short sentence, so that is reasonable. But how would I know how big to make the output buffer? Or will Deflater (and Inflater) adjust the size of the output buffer as needed?
Instead of guessing at the size of a buffer, can I use ByteArrayOutputStream and wrap a DeflatorOutputStream around that? Since ByteArrayOutputStream changes the size of the byte array, it wouldn't be necessary to know the size of the output or guess at it, as it seems one would have to do in the API example.
1.In the API documentation example, the output buffer for both the Inflater and Deflater is set at 1024 bytes. The example data is only a short sentence, so that is reasonable. But how would I know how big to make the output buffer? Or will Deflater (and Inflater) adjust the size of the output buffer as needed?
In streams, buffers are just temporary space before passing onto the another stream. Changing the buffers size can change performance but has little to do with the amount of data processed.
2.Instead of guessing at the size of a buffer, can I use ByteArrayOutputStream and wrap a DeflatorOutputStream around that? Since ByteArrayOutputStream changes the size of the byte array, it wouldn't be necessary to know the size of the output or guess at it, as it seems one would have to do in the API example.
You can do that, or you can send it directly to the stream you want the data to go to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With