public void close() throws IOException {
        // Append the footer before draining the batch accumulator and force it to create a batch
        batchAccumulator.appendSnapshotFooterRecord(
            new SnapshotFooterRecord()
                .setVersion(ControlRecordUtils.SNAPSHOT_FOOTER_CURRENT_VERSION),
            time.milliseconds()
        );
        batchAccumulator.forceDrain();

        try {
            for (BatchAccumulator.CompletedBatch<ApiMessageAndVersion> batch : batchAccumulator.drain()) {
                Utils.writeFully(channel, batch.data.buffer());
            }
        } finally {
            batchAccumulator.close();
            channel.close();
        }
    }
Write an arbitrary set of metadata records into a Kafka metadata log batch format.

This is similar to the binary format used for metadata snapshot files, but the log epoch
and initial offset are set to zero. This type includes a SnapshotHeaderRecord record in the
first batch and a SnapshotFooterRecord record in the last batch.
metadata/src/main/java/org/apache/kafka/metadata/util/BatchFileWriter.java