@Nullable
    public Charset charset() {
        // racy single-check idiom, this is safe because Optional is immutable.
        Charset local = parsedCharset;
        if (local == null) {
            String value = null;
            local = NO_CHARSET;
            for (String currentValue : parameters.get(CHARSET_ATTRIBUTE)) {
                if (value == null) {
                    value = currentValue;
                    local = Charset.forName(value);
                } else if (!value.equals(currentValue)) {
                    throw new IllegalStateException(
                            "Multiple charset values defined: " + value + ", " + currentValue);
                }
            }
            parsedCharset = local;
        }
        return local != NO_CHARSET ? local : null;
    }
Returns a {@link Charset} for the value of the charset parameter if it is specified.

@return the {@link Charset}, or {@code null} if the charset parameter is not specified.

@throws IllegalStateException if multiple charset values have been set for this media type
@throws IllegalCharsetNameException if a charset value is present, but illegal
@throws UnsupportedCharsetException if a charset value is present, but no support is available
                                    in this instance of the Java virtual machine
core/src/main/java/com/linecorp/armeria/common/MediaType.java