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.