public void write(ImageWriter writer, ImageWriterOptions options) {
        if (options.metadataVersion().isScramSupported()) {
            for (Entry<ScramMechanism, Map<String, ScramCredentialData>> mechanismEntry : mechanisms.entrySet()) {
                for (Entry<String, ScramCredentialData> userEntry : mechanismEntry.getValue().entrySet()) {
                    writer.write(0, userEntry.getValue().toRecord(userEntry.getKey(), mechanismEntry.getKey()));
                }
            }
        } else {
            boolean isEmpty = true;
            StringBuilder scramImageString = new StringBuilder("ScramImage({");
            for (Entry<ScramMechanism, Map<String, ScramCredentialData>> mechanismEntry : mechanisms.entrySet()) {
                if (!mechanismEntry.getValue().isEmpty()) {
                    scramImageString.append(mechanismEntry.getKey()).append(":");
                    List<String> users = new ArrayList<>(mechanismEntry.getValue().keySet());
                    scramImageString.append(String.join(", ", users));
                    scramImageString.append("},{");
                    isEmpty = false;
                }
            }

            if (!isEmpty) {
                scramImageString.append("})");
                options.handleLoss(scramImageString.toString());
            }
        }
    }
Represents the SCRAM credentials in the metadata image.

This class is thread-safe.
metadata/src/main/java/org/apache/kafka/image/ScramImage.java