Class MediaType

  • All Implemented Interfaces:
    LazyValueBytesRenderable, Renderable, MediaType, WithQValue<MediaRange>
    Direct Known Subclasses:
    MediaType.Binary, MediaType.NonBinary

    public abstract class MediaType
    extends java.lang.Object
    implements MediaType, LazyValueBytesRenderable, WithQValue<MediaRange>
    A MediaType describes the type of the content of an HTTP message entity.

    While knowledge of the MediaType alone suffices for being able to properly interpret binary content this is not generally the case for non-binary (i.e. character-based) content, which also requires the definition of a specific character encoding (HttpCharset). Therefore MediaType instances are frequently encountered as a member of a ContentType, which groups a MediaType with a potentially required HttpCharset to hold everything required for being able to interpret an HttpEntity.

    MediaTypes come in three basic forms:

    1. Binary: These do not need an additional HttpCharset to be able to form a ContentType. Therefore they can be implicitly converted to the latter.

    2. WithOpenCharset: Most character-based MediaTypes are of this form, which can be combined with all HttpCharset instances to form a ContentType.

    3. WithFixedCharset: Some character-based MediaTypes prescribe a single, clearly defined charset and as such, similarly to binary MediaTypes, do not require the addition of an HttpCharset instances to form a ContentType. The most prominent example is probably application/json which must always be UTF-8 encoded. Like binary MediaTypes WithFixedCharset types can be implicitly converted to a ContentType.

    Not for user extension.

    • Constructor Detail

      • MediaType

        public MediaType​(java.lang.String _mainType,
                         java.lang.String _subType)
    • Method Detail

      • applicationWithFixedCharset

        public static MediaType.WithFixedCharset applicationWithFixedCharset​(java.lang.String subType,
                                                                             HttpCharset charset,
                                                                             scala.collection.immutable.Seq<java.lang.String> fileExtensions)
      • applicationWithOpenCharset

        public static MediaType.WithOpenCharset applicationWithOpenCharset​(java.lang.String subType,
                                                                           scala.collection.immutable.Seq<java.lang.String> fileExtensions)
      • text

        public static MediaType.WithOpenCharset text​(java.lang.String subType,
                                                     scala.collection.immutable.Seq<java.lang.String> fileExtensions)
      • textWithFixedCharset

        public static MediaType.WithFixedCharset textWithFixedCharset​(java.lang.String subType,
                                                                      HttpCharset charset,
                                                                      scala.collection.immutable.Seq<java.lang.String> fileExtensions)
      • customBinary

        public static MediaType.Binary customBinary​(java.lang.String mainType,
                                                    java.lang.String subType,
                                                    MediaType.Compressibility comp,
                                                    scala.collection.immutable.List<java.lang.String> fileExtensions,
                                                    scala.collection.immutable.Map<java.lang.String,​java.lang.String> params,
                                                    boolean allowArbitrarySubtypes)
      • customWithFixedCharset

        public static MediaType.WithFixedCharset customWithFixedCharset​(java.lang.String mainType,
                                                                        java.lang.String subType,
                                                                        HttpCharset charset,
                                                                        scala.collection.immutable.List<java.lang.String> fileExtensions,
                                                                        scala.collection.immutable.Map<java.lang.String,​java.lang.String> params,
                                                                        boolean allowArbitrarySubtypes)
      • customWithOpenCharset

        public static MediaType.WithOpenCharset customWithOpenCharset​(java.lang.String mainType,
                                                                      java.lang.String subType,
                                                                      scala.collection.immutable.List<java.lang.String> fileExtensions,
                                                                      scala.collection.immutable.Map<java.lang.String,​java.lang.String> params,
                                                                      boolean allowArbitrarySubtypes)
      • customMultipart

        public static MediaType.Multipart customMultipart​(java.lang.String subType,
                                                          scala.collection.immutable.Map<java.lang.String,​java.lang.String> params)
      • custom

        public static MediaType custom​(java.lang.String value,
                                       boolean binary,
                                       MediaType.Compressibility comp,
                                       scala.collection.immutable.List<java.lang.String> fileExtensions)
      • parse

        public static scala.util.Either<scala.collection.immutable.List<ErrorInfo>,​MediaType> parse​(java.lang.String value)
        Tries to parse a MediaType value from the given String. Returns Right(mediaType) if successful and Left(errors) otherwise.
        Parameters:
        value - (undocumented)
        Returns:
        (undocumented)
      • unapply

        public static scala.Option<java.lang.String> unapply​(MediaType mediaType)
      • mainType

        public java.lang.String mainType()
        Description copied from interface: MediaType
        The main-type of this media-type.
        Specified by:
        mainType in interface MediaType
        Returns:
        (undocumented)
      • subType

        public java.lang.String subType()
        Description copied from interface: MediaType
        The sub-type of this media-type.
        Specified by:
        subType in interface MediaType
        Returns:
        (undocumented)
      • fileExtensions

        public abstract scala.collection.immutable.List<java.lang.String> fileExtensions()
      • params

        public abstract scala.collection.immutable.Map<java.lang.String,​java.lang.String> params()
      • isAudio

        public boolean isAudio()
        Specified by:
        isAudio in interface MediaType
      • isImage

        public boolean isImage()
        Specified by:
        isImage in interface MediaType
      • isText

        public boolean isText()
        Specified by:
        isText in interface MediaType
      • isVideo

        public boolean isVideo()
        Specified by:
        isVideo in interface MediaType
      • withParams

        public abstract MediaType withParams​(scala.collection.immutable.Map<java.lang.String,​java.lang.String> params)
      • equals

        public boolean equals​(java.lang.Object that)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toRange

        public MediaRange toRange​(float qValue)
        Description copied from interface: MediaType
        Creates a media-range from this media-type with a given qValue.
        Specified by:
        toRange in interface MediaType
        Parameters:
        qValue - (undocumented)
        Returns:
        (undocumented)
      • isCompressible

        public boolean isCompressible()
        Description copied from interface: MediaType
        True when this media-type is generally compressible.
        Specified by:
        isCompressible in interface MediaType
        Returns:
        (undocumented)