Finalize the export and write the data to the given output. This method should be called after all the data was added.