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'sflush()method inherited fromDeflaterOutputStreamrelies upon the flush mode specified at construction time with thesyncFlushargument (related toDeflater#SYNC_FLUSH) to decide whether to flush the pending data to be compressed. ThissyncFlushargument is also accepted byGZIPOutputStreamat construction time.It sounds like you want to use either
Deflator#SYNC_FLUSHor maybe evenDeflater#FULL_FLUSH, but, before digging down that far, first try working with the two-argument or the four-argumentGZIPOutputStreamconstructor and passtruefor thesyncFlushargument. That will activate the flushing behavior you desire.