Class MediaType


  • public class MediaType
    extends java.lang.Object
    Represents a (simplified) Media Type.
    Since:
    0.7.0
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  MediaType.Type
      Represents the type of a Media Type
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static MediaType application​(java.lang.String subType)
      Creates a binary application media type with the given subtype.
      static MediaType applicationUtf8​(java.lang.String subType)
      Creates a textual application media type with the given subtype and UTF-8 encoding
      java.lang.String asString()  
      static MediaType audio​(java.lang.String subType)
      Creates a binary audio media type with the given subtype.
      static MediaType binary​(MediaType.Type type, java.lang.String subType)
      Creates a binary media type with the given type and subtype
      java.nio.charset.Charset getCharset()  
      java.lang.String getSubType()
      The subtype of the Media Type.
      MediaType.Type getType()
      The type of the Media Type.
      static MediaType image​(java.lang.String subType)
      Creates a binary image media type with the given subtype.
      static MediaType imageUtf8​(java.lang.String subType)
      Creates a textual image media type with the given subtype and UTF-8 encoding
      boolean isBinary()
      Whether this media type is binary or not.
      boolean isImage()  
      static MediaType nonBinary​(MediaType.Type type, java.lang.String subType, java.nio.charset.Charset charSet)
      Creates a non-binary media type with the given type, subtype, and charSet
      static MediaType nonBinaryUtf8​(MediaType.Type type, java.lang.String subType)
      Creates a non-binary media type with the given type, subtype, and UTF-8 encoding
      static MediaType text​(java.lang.String subType, java.nio.charset.Charset charset)
      Creates a non-binary text media type with the given subtype and a specified encoding
      static MediaType textUtf8​(java.lang.String subType)
      Creates a non-binary text media type with the given subtype.
      java.lang.String toString()  
      static MediaType video​(java.lang.String subType)
      Creates a binary video media type with the given subtype.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • GIF

        public static final MediaType GIF
        image/gif
      • PNG

        public static final MediaType PNG
        image/png
      • JPEG

        public static final MediaType JPEG
        image/jpeg
      • SVG_UTF_8

        public static final MediaType SVG_UTF_8
        image/svg+xml
      • PLAIN_TEXT_UTF_8

        public static final MediaType PLAIN_TEXT_UTF_8
        text/plain
      • JSON_UTF_8

        public static final MediaType JSON_UTF_8
        application/json
      • APPLICATION_XML_UTF_8

        public static final MediaType APPLICATION_XML_UTF_8
        application/xml
      • XML_UTF_8

        public static final MediaType XML_UTF_8
        text/xml
    • Method Detail

      • getType

        public MediaType.Type getType()
        The type of the Media Type.
      • getSubType

        public java.lang.String getSubType()
        The subtype of the Media Type.
      • isBinary

        public boolean isBinary()
        Whether this media type is binary or not.
      • isImage

        public boolean isImage()
      • getCharset

        public java.nio.charset.Charset getCharset()
        Returns:
        the charset of this media type if one is specified
        Throws:
        java.lang.IllegalArgumentException - if no charset is specified
      • asString

        public java.lang.String asString()
      • nonBinary

        public static MediaType nonBinary​(MediaType.Type type,
                                          java.lang.String subType,
                                          java.nio.charset.Charset charSet)
        Creates a non-binary media type with the given type, subtype, and charSet
        Throws:
        JGivenWrongUsageException - if any of the given arguments is null
      • nonBinaryUtf8

        public static MediaType nonBinaryUtf8​(MediaType.Type type,
                                              java.lang.String subType)
        Creates a non-binary media type with the given type, subtype, and UTF-8 encoding
        Throws:
        JGivenWrongUsageException - if any of the given arguments is null
      • image

        public static MediaType image​(java.lang.String subType)
        Creates a binary image media type with the given subtype.
      • imageUtf8

        public static MediaType imageUtf8​(java.lang.String subType)
        Creates a textual image media type with the given subtype and UTF-8 encoding
      • application

        public static MediaType application​(java.lang.String subType)
        Creates a binary application media type with the given subtype.
      • applicationUtf8

        public static MediaType applicationUtf8​(java.lang.String subType)
        Creates a textual application media type with the given subtype and UTF-8 encoding
      • video

        public static MediaType video​(java.lang.String subType)
        Creates a binary video media type with the given subtype.
      • audio

        public static MediaType audio​(java.lang.String subType)
        Creates a binary audio media type with the given subtype.
      • text

        public static MediaType text​(java.lang.String subType,
                                     java.nio.charset.Charset charset)
        Creates a non-binary text media type with the given subtype and a specified encoding
      • textUtf8

        public static MediaType textUtf8​(java.lang.String subType)
        Creates a non-binary text media type with the given subtype.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object