Record Class MediaType

java.lang.Object
java.lang.Record
org.htmlunit.csp.value.MediaType
Record Components:
type - the primary type in lowercase (e.g. "application")
subtype - the subtype in lowercase (e.g. "pdf")

public record MediaType(String type, String subtype) extends Record
Represents a media type (MIME type) value used by the (deprecated) plugin-types CSP directive, e.g. application/pdf.

A media type consists of a type and a subtype separated by a forward slash. Matching is ASCII case-insensitive per the plugin-types post-request check, so both parts are stored in lowercase.

Author:
Salvation Team
  • Constructor Details

    • MediaType

      public MediaType(String type, String subtype)
      Creates an instance of a MediaType record class.
      Parameters:
      type - the value for the type record component
      subtype - the value for the subtype record component
  • Method Details

    • parseMediaType

      public static Optional<MediaType> parseMediaType(String value)
      Parses a media type from its string representation.

      The input must match the type/subtype grammar. Both parts are lowercased for case-insensitive matching.

      Parameters:
      value - the media type string (e.g. "application/pdf")
      Returns:
      an Optional containing the parsed MediaType, or empty if the value does not match the media-type grammar
    • toString

      public String toString()
      Returns the media type in its canonical type/subtype form (e.g. "application/pdf").
      Specified by:
      toString in class Record
      Returns:
      the media type string
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • type

      public String type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • subtype

      public String subtype()
      Returns the value of the subtype record component.
      Returns:
      the value of the subtype record component