2010-02-24

GZipOutputStream: Remember to finish() what you start!

Had an interesting experience the other day. I was creating a stream of compressed data using GZipOutputStream and ended up with lots of missing data.

It turns out that data will (may?) not be properly written to the output stream if you neglect to call finish() when you're done pumping data in. Strangely enough, neither flush() nor even close() are sufficient to accomplish this; it's either finish() or you risk having corrupt, incomplete data in your output.