Class MediaType

java.lang.Object
org.faceless.publisher.type.MediaType
All Implemented Interfaces:
Serializable

public class MediaType extends Object implements Serializable
A simple class representing a Media-Type (aka Content-Type or MIME-Type).
See Also:
  • Field Details

    • WILDCARD

      public static final MediaType WILDCARD
      The wildcard MediaType */*
  • Constructor Details

    • MediaType

      public MediaType(String type, String subtype)
      Create a MediaType from the specified parameters
      Parameters:
      type - the type, eg "image", or null for wildcard
      subtype - the subtype, eg "png", or null for wildcard
  • Method Details

    • parse

      public static MediaType parse(String s)
      Returns a Media-Type for this String, or null if it is not well-formed.
    • parse

      public static MediaType parse(String s, boolean strict)
      Returns a Media-Type for this String, or null if it is not well-formed.
      Parameters:
      strict - if false, do your best to return something even if its not strictly valid.
    • getType

      public String getType()
      Return the type, or null for wildcard
    • getSubType

      public String getSubType()
      Return the subtype, or null for wildcard
    • isWildcard

      public boolean isWildcard()
      Return true if neither the type nor subtype are defined
    • hasWildcard

      public boolean hasWildcard()
      Return true if either the type or subtype are undefined
    • isXMLBased

      public boolean isXMLBased()
      Return true if the subtype is "xml", or ends in "+xml"
    • matches

      public boolean matches(String type)
      Return true if this MediaType matches the specified type. This type must not have wildcards to match; the specified type may have wildcards.
    • matches

      public boolean matches(String type, String subtype)
      Return true if this MediaType matches the specified type/subtype. This type must not have wildcards to match; the specified type/subtype may have wildcards.
    • matches

      public boolean matches(MediaType m)
      Return true if this MediaType matches the specified type. This type must not have wildcards to match; the specified type may have wildcards.
    • getBase

      public String getBase()
      Return type/subtype
    • getParameter

      public String getParameter(String key)
      Return the named parameter, or null if it doesn't exist
    • newType

      public MediaType newType(String type, String subtype)
      Return a new MediaType that is a clone of the current one with a new type/subtype
    • newParameter

      public MediaType newParameter(String key, String value)
      Set the named parameter in a new copy of this object and return it. If value is a string, use it. If value is an empty String, set it with no value (eg "base64"). If value is null, remove it
    • getParameters

      public Map<String,String> getParameters()
      Return a read-only map of the parameters
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object