we are working on a program where we need to flush (force compress and send data) a GZIPOutputStream. The problem is, that the flush method of the GZIPOutputStream doesn't work as expected (force compress and send data), instead the Stream waits for more data for efficient data compression.
When you call finish the data is compressed and sent over the output stream but the GZIPOutputStream (not the underlying stream) will be closed so we cant write more data till we create a new GZIPOutputStream, which costs time and performance.
Hope anyone can help with this.
Best regards.
I haven't tried this yet, and this advice won't be useful until we have Java 7 in hand, but the documentation for GZIPOutputStream
's flush()
method inherited from DeflaterOutputStream
relies upon the flush mode specified at construction time with the syncFlush
argument (related to Deflater#SYNC_FLUSH
) to decide whether to flush the pending data to be compressed. This syncFlush
argument is also accepted by GZIPOutputStream
at construction time.
It sounds like you want to use either Deflator#SYNC_FLUSH
or maybe even Deflater#FULL_FLUSH
, but, before digging down that far, first try working with the two-argument or the four-argument GZIPOutputStream
constructor and pass true
for the syncFlush
argument. That will activate the flushing behavior you desire.
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