public void writeBinaryFile(BootstrapMetadata bootstrapMetadata) throws IOException {
        if (!Files.isDirectory(Paths.get(directoryPath))) {
            throw new RuntimeException("No such directory as " + directoryPath);
        }
        Path tempPath = Paths.get(directoryPath, BINARY_BOOTSTRAP_FILENAME + ".tmp");
        Files.deleteIfExists(tempPath);
        try {
            try (BatchFileWriter writer = BatchFileWriter.open(tempPath)) {
                for (ApiMessageAndVersion message : bootstrapMetadata.records()) {
                    writer.append(message);
                }
            }

            Files.move(
                tempPath,
                Paths.get(directoryPath, BINARY_BOOTSTRAP_FILENAME),
                ATOMIC_MOVE, REPLACE_EXISTING
            );
        } finally {
            Files.deleteIfExists(tempPath);
        }
    }
Create a new BootstrapDirectory object.

@param directoryPath     The path to the directory with the bootstrap file.
@param ibp               The configured value of inter.broker.protocol, or the empty string
                         if it is not configured.
metadata/src/main/java/org/apache/kafka/metadata/bootstrap/BootstrapDirectory.java