Module io.jooby
Package io.jooby

Class MediaType

java.lang.Object
io.jooby.MediaType
All Implemented Interfaces:
Comparable<MediaType>

public final class MediaType extends Object implements Comparable<MediaType>
Implementation of media/content type.
Since:
2.0.0
  • Field Details

  • Method Details

    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

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

      @Nullable public String getParameter(@NonNull String name)
      Get a parameter that matches the given name or null.
      Parameters:
      name - Parameter name.
      Returns:
      Parameter value or null.
    • getValue

      @NonNull public String getValue()
      Media type value without parameters.
      Returns:
      Media type value.
    • toContentTypeHeader

      @NonNull public String toContentTypeHeader(@Nullable Charset charset)
      Render a content type header and add the charset parameter (when present).
      Parameters:
      charset - Charset.
      Returns:
      Content type header.
    • getQuality

      @NonNull public float getQuality()
      Value of q parameter.
      Returns:
      Value of q parameter.
    • compareTo

      public int compareTo(MediaType other)
      Specified by:
      compareTo in interface Comparable<MediaType>
    • isTextual

      public boolean isTextual()
      Indicates whenever this is a textual mediatype.
      Returns:
      True for textual mediatype.
    • isJson

      public boolean isJson()
      Indicates whenever this is a json mediatype.
      Returns:
      True for json mediatype.
    • getCharset

      @Nullable public Charset getCharset()
      Charset or null.
      Returns:
      Charset or null.
    • getType

      @NonNull public String getType()
      Type segment of mediatype (leading type).
      Returns:
      Type segment of mediatype (leading type).
    • getSubtype

      @NonNull public String getSubtype()
      Subtype segment of mediatype (trailing type).
      Returns:
      Subtype segment of mediatype (trailing type).
    • matches

      public boolean matches(@NonNull String mediaType)
      True if this mediatype is compatible with the given content type.
      Parameters:
      mediaType - Media type to test.
      Returns:
      True if this mediatype is compatible with the given content type.
    • matches

      public boolean matches(@NonNull MediaType type)
      True if this mediatype is compatible with the given content type.
      Parameters:
      type - Media type to test.
      Returns:
      True if this mediatype is compatible with the given content type.
    • valueOf

      @NonNull public static MediaType valueOf(@NonNull String value)
      Parse a string value into a media-type.
      Parameters:
      value - String media-type.
      Returns:
      Media type.
    • parse

      @NonNull public static List<MediaType> parse(@Nullable String value)
      Parse one or more mediatype values. Mediatype must be separated by comma ,.
      Parameters:
      value - Mediatype comma separated value.
      Returns:
      One or more mediatypes.
    • byFile

      @NonNull public static MediaType byFile(@NonNull File file)
      Mediatype by file extension.
      Parameters:
      file - File.
      Returns:
      Mediatype.
    • byFile

      @NonNull public static MediaType byFile(@NonNull Path file)
      Mediatype by file extension.
      Parameters:
      file - File.
      Returns:
      Mediatype.
    • byFile

      @NonNull public static MediaType byFile(@NonNull String filename)
      Mediatype by file extension.
      Parameters:
      filename - File.
      Returns:
      Mediatype.
    • byFileExtension

      @NonNull public static MediaType byFileExtension(@NonNull String ext)
      Mediatype by file extension.
      Parameters:
      ext - File extension.
      Returns:
      Mediatype.
    • toString

      public String toString()
      Overrides:
      toString in class Object