Closes the encoder, ensuring all data is written. Closing the encoder also closes the underlying sink.
If an I/O error occurs.