类 MimeType

java.lang.Object
cn.taketoday.util.MimeType
所有已实现的接口:
Serializable, Comparable<MimeType>

public class MimeType extends Object implements Comparable<MimeType>, Serializable
Represents a MIME Type, as originally defined in RFC 2046 and subsequently used in other Internet protocols including HTTP.

This class, however, does not contain support for the q-parameters used in HTTP content negotiation. Those can be found in the subclass MediaType in the today-web module.

Consists of a type and a subtype. Also has functionality to parse MIME Type values from a String using valueOf(String). For more parsing options see MimeTypeUtils.

从以下版本开始:
2.1.7 2019-12-08 19:08
作者:
Arjen Poutsma, Juergen Hoeller, Rossen Stoyanchev, Sam Brannen, Harry Yang
另请参阅:
  • 字段详细资料

  • 构造器详细资料

    • MimeType

      public MimeType(String type)
      Create a new MimeType for the given primary type.

      The subtype is set to "*", and the parameters are empty.

      参数:
      type - the primary type
      抛出:
      IllegalArgumentException - if any of the parameters contains illegal characters
    • MimeType

      public MimeType(String type, String subtype)
      Create a new MimeType for the given primary type and subtype.

      The parameters are empty.

      参数:
      type - the primary type
      subtype - the subtype
      抛出:
      IllegalArgumentException - if any of the parameters contains illegal characters
    • MimeType

      public MimeType(String type, String subtype, Charset charset)
      Create a new MimeType for the given type, subtype, and character set.
      参数:
      type - the primary type
      subtype - the subtype
      charset - the character set
      抛出:
      IllegalArgumentException - if any of the parameters contains illegal characters
    • MimeType

      public MimeType(MimeType other, Charset charset)
      Copy-constructor that copies the type, subtype, parameters of the given MimeType, and allows to set the specified character set.
      参数:
      other - the other MimeType
      charset - the character set
      抛出:
      IllegalArgumentException - if any of the parameters contains illegal characters
    • MimeType

      public MimeType(MimeType other, @Nullable Map<String,String> parameters)
      Copy-constructor that copies the type and subtype of the given MimeType, and allows for different parameter.
      参数:
      other - the other MimeType
      parameters - the parameters (may be null)
      抛出:
      IllegalArgumentException - if any of the parameters contains illegal characters
    • MimeType

      public MimeType(String type, String subtype, @Nullable Map<String,String> parameters)
      Create a new MimeType for the given type, subtype, and parameters.
      参数:
      type - the primary type
      subtype - the subtype
      parameters - the parameters (maybe null)
      抛出:
      IllegalArgumentException - if any of the parameters contains illegal characters
    • MimeType

      protected MimeType(MimeType other)
      Copy-constructor that copies the type, subtype and parameters of the given MimeType, skipping checks performed in other constructors.
      参数:
      other - the other MimeType
      从以下版本开始:
      3.0
  • 方法详细资料

    • checkToken

      private static void checkToken(String token)
      Checks the given token string for illegal characters, as defined in RFC 2616, section 2.2.
      抛出:
      IllegalArgumentException - in case of illegal characters
      另请参阅:
    • checkParameters

      protected void checkParameters(String attribute, String value)
    • isQuotedString

      private boolean isQuotedString(String s)
    • unquote

      protected String unquote(String s)
    • isWildcardType

      public boolean isWildcardType()
      Indicates whether the type is the wildcard character * or not.
    • isWildcardSubtype

      public boolean isWildcardSubtype()
      Indicates whether the subtype is the wildcard character * or the wildcard character followed by a suffix (e.g. *+xml).
      返回:
      whether the subtype is a wildcard
    • isConcrete

      public boolean isConcrete()
      Indicates whether this MIME Type is concrete, i.e. whether neither the type nor the subtype is a wildcard character *.
      返回:
      whether this MIME Type is concrete
    • getType

      public String getType()
      Return the primary type.
    • getSubtype

      public String getSubtype()
      Return the subtype.
    • getSubtypeSuffix

      @Nullable public String getSubtypeSuffix()
      Return the subtype suffix as defined in RFC 6839.
      从以下版本开始:
      4.0
    • getCharset

      @Nullable public Charset getCharset()
      Return the character set, as indicated by a charset parameter, if any.
      返回:
      the character set, or null if not available
    • getParameter

      @Nullable public String getParameter(String name)
      Return a generic parameter value, given a parameter name.
      参数:
      name - the parameter name
      返回:
      the parameter value, or null if not present
    • getParameters

      public Map<String,String> getParameters()
      Return all generic parameter values.
      返回:
      a read-only map (possibly empty, never null)
    • includes

      public boolean includes(@Nullable MimeType other)
      Indicate whether this MIME Type includes the given MIME Type.

      For instance, text/* includes text/plain and text/html, and application/*+xml includes application/soap+xml, etc. This method is not symmetric.

      参数:
      other - the reference MIME Type with which to compare
      返回:
      true if this MIME Type includes the given MIME Type; false otherwise
    • isCompatibleWith

      public boolean isCompatibleWith(@Nullable MimeType other)
      Indicate whether this MIME Type is compatible with the given MIME Type.

      For instance, text/* is compatible with text/plain, text/html, and vice versa. In effect, this method is similar to includes(cn.taketoday.util.MimeType), except that it is symmetric.

      参数:
      other - the reference MIME Type with which to compare
      返回:
      true if this MIME Type is compatible with the given MIME Type; false otherwise
    • equalsTypeAndSubtype

      public boolean equalsTypeAndSubtype(@Nullable MimeType other)
      Similar to equals(Object) but based on the type and subtype only, i.e. ignoring parameters.
      参数:
      other - the other mime type to compare to
      返回:
      whether the two mime types have the same type and subtype
    • isPresentIn

      public boolean isPresentIn(Collection<? extends MimeType> mimeTypes)
      Unlike Collection.contains(Object) which relies on equals(Object), this method only checks the type and the subtype, but otherwise ignores parameters.
      参数:
      mimeTypes - the list of mime types to perform the check against
      返回:
      whether the list contains the given mime type
    • equals

      public boolean equals(Object other)
      覆盖:
      equals 在类中 Object
    • parametersAreEqual

      private boolean parametersAreEqual(MimeType other)
      Determine if the parameters in this MimeType and the supplied MimeType are equal, performing case-insensitive comparisons for Charsets.
    • hashCode

      public int hashCode()
      覆盖:
      hashCode 在类中 Object
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object
    • appendTo

      protected void appendTo(StringBuilder builder)
    • appendTo

      private void appendTo(Map<String,String> map, StringBuilder builder)
    • compareTo

      public int compareTo(MimeType other)
      Compares this MIME Type to another alphabetically.
      指定者:
      compareTo 在接口中 Comparable<MimeType>
      参数:
      other - the MIME Type to compare to
    • isMoreSpecific

      public boolean isMoreSpecific(MimeType other)
      Indicates whether this MimeType is more specific than the given type.
      1. if this mime type has a wildcard type, and the other does not, then this method returns false.
      2. if this mime type does not have a wildcard type, and the other does, then this method returns true.
      3. if this mime type has a wildcard type, and the other does not, then this method returns false.
      4. if this mime type does not have a wildcard type, and the other does, then this method returns true.
      5. if the two mime types have identical type and subtype, then the mime type with the most parameters is more specific than the other.
      6. Otherwise, this method returns false.
      参数:
      other - the MimeType to be compared
      返回:
      the result of the comparison
      从以下版本开始:
      4.0
      另请参阅:
    • isLessSpecific

      public boolean isLessSpecific(MimeType other)
      Indicates whether this MimeType is more less than the given type.
      1. if this mime type has a wildcard type, and the other does not, then this method returns true.
      2. if this mime type does not have a wildcard type, and the other does, then this method returns false.
      3. if this mime type has a wildcard type, and the other does not, then this method returns true.
      4. if this mime type does not have a wildcard type, and the other does, then this method returns false.
      5. if the two mime types have identical type and subtype, then the mime type with the least parameters is less specific than the other.
      6. Otherwise, this method returns false.
      参数:
      other - the MimeType to be compared
      返回:
      the result of the comparison
      从以下版本开始:
      4.0
      另请参阅:
    • readObject

      private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException
      抛出:
      IOException
      ClassNotFoundException
    • valueOf

      public static MimeType valueOf(String value)
      另请参阅:
    • addCharsetParameter

      private static Map<String,String> addCharsetParameter(Charset charset, Map<String,String> parameters)