Class MediaType.Parameter

All Implemented Interfaces:
IDed<String>, Named<String>, Valued<String>
Enclosing class:
MediaType

public static final class MediaType.Parameter extends NameValuePair<String,String>
A media type parameter name/value pair. Neither the name nor the value of a media type parameter can be null.
Author:
Garret Wilson
Implementation Specification:
This class normalizes parameter names, which are ASCII case-insensitive, to lowercase; along with the charset parameter value. All other parameter values are left as-is. All other parameter values that are case-insensitive should be passed as lowercase to ensure correct equality comparisons., This implementation does not allow control characters.
Implementation Note:
Compare this implementation to that of Guava's com.google.common.net.MediaType which, in addition to normalizing type, subtype, and parameter names to lowercase, also normalizes the value of the charset attribute to lowercase. Note also that RFC 7231 § 3.1.1.1. Media Type indicates that a lowercase form of charset value is preferred, e.g.text/html;charset=utf-8. In addition RFC 2046 § 4.1.2. Charset Parameter indicates that if non-text types specify a charset value, "the same syntax and values should be used"., This class considers value quoting a syntax issue of serialization, and thus interprets all values as logical, non-quoted values.
  • Field Details

  • Constructor Details

  • Method Details

    • of

      public static MediaType.Parameter of(@Nonnull String name, @Nonnull String value)
      Static factory method specifying the name and value.
      Implementation Specification:
      The parameter name is normalized to lowercase. The value of the "charset" parameter is normalized to lowercase.
      Parameters:
      name - The parameter name.
      value - The parameter value.
      Returns:
      A media type for the indicated name and value.
      Throws:
      NullPointerException - if the given name and/or value is null.
      IllegalArgumentException - if the name does not conform to the MediaType.RESTRICTED_NAME_PATTERN pattern.
      IllegalArgumentException - if the parameter value includes control characters.
    • parseValue

      public static String parseValue(CharSequence text)
      Parses a parameter of a media type from a sequence of characters. Quoted/escaped values are supported and decoded, but otherwise no normalization is performed.
      Implementation Specification:
      This implementation supports an empty string value only if it is quoted., This implementation allows any character except control characters to be escaped., This implementation does not allow control characters other than horizontal tab.
      Parameters:
      text - The character sequence representing the parameters of the value.
      Returns:
      The parsed value.
      Throws:
      IllegalArgumentException - if the string is not syntactically correct parameters, or if a parameter name does not conform to the MediaType.RESTRICTED_NAME_PATTERN pattern.
    • toValueString

      public String toValueString()
      Returns a string representation of the value, quoting and escaping it as necessary.
      API Note:
      This method differs from NameValuePair.getValue(), which returns the raw value with no quoting or escaping.
      Implementation Specification:
      This implementation delegates to appendValueTo(Appendable, CharSequence)., This implementation does not allow control characters.
      Returns:
      The string version of the value.
    • appendValueTo

      public static <A extends Appendable> A appendValueTo(@Nonnull A appendable, @Nonnull CharSequence parameterValue) throws IOException
      Appends a string representing a parameter value to an appendable, quoting and escaping it as necessary.
      Implementation Specification:
      This implementation does not allow control characters other than horizontal tab., This implementation quotes empty strings.
      Type Parameters:
      A - The type of appendable being used.
      Parameters:
      appendable - The appendable, such as a StringBuilder, to which the value should be appended.
      parameterValue - The parameter value.
      Returns:
      The given appendable.
      Throws:
      IllegalArgumentException - if the parameter value includes control characters.
      IOException - If an I/O error occurs appending the value.