Class MediaType
- All Implemented Interfaces:
LazyValueBytesRenderable,Renderable,MediaType,WithQValue<MediaRange>
- Direct Known Subclasses:
MediaType.Binary,MediaType.NonBinary
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic classstatic classstatic final classstatic classstatic classstatic classstatic classstatic class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MediaType.BinaryapplicationBinary(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) static MediaType.WithFixedCharsetapplicationWithFixedCharset(String subType, HttpCharset charset, scala.collection.immutable.Seq<String> fileExtensions) static MediaType.WithOpenCharsetapplicationWithOpenCharset(String subType, scala.collection.immutable.Seq<String> fileExtensions) static MediaType.Binaryaudio(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) abstract MediaType.Compressibilitycomp()static MediaTypecustom(String value, boolean binary, MediaType.Compressibility comp, scala.collection.immutable.List<String> fileExtensions) static MediaType.BinarycustomBinary(String mainType, String subType, MediaType.Compressibility comp, scala.collection.immutable.List<String> fileExtensions, scala.collection.immutable.Map<String, String> params, boolean allowArbitrarySubtypes) static MediaType.MultipartcustomMultipart(String subType, scala.collection.immutable.Map<String, String> params) static MediaType.WithFixedCharsetcustomWithFixedCharset(String mainType, String subType, HttpCharset charset, scala.collection.immutable.List<String> fileExtensions, scala.collection.immutable.Map<String, String> params, boolean allowArbitrarySubtypes) static MediaType.WithOpenCharsetcustomWithOpenCharset(String mainType, String subType, scala.collection.immutable.List<String> fileExtensions, scala.collection.immutable.Map<String, String> params, boolean allowArbitrarySubtypes) booleanabstract scala.collection.immutable.List<String>static MediaType.Binaryfont(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) inthashCode()static MediaType.Binaryimage(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) booleanbooleanisAudio()booleanTrue when this media-type is generally compressible.booleanisImage()booleanbooleanbooleanisText()booleanisVideo()mainType()The main-type of this media-type.static MediaType.Binarymessage(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) params()Tries to parse aMediaTypevalue from the given String.subType()The sub-type of this media-type.static MediaType.WithOpenCharsetstatic MediaType.WithFixedCharsettextWithFixedCharset(String subType, HttpCharset charset, scala.collection.immutable.Seq<String> fileExtensions) toRange()JAVA APItoRange(float qValue) Creates a media-range from this media-type with a given qValue.static scala.Option<String>static MediaType.Binaryvideo(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) abstract MediaTypeabstract MediaTypewithParams(scala.collection.immutable.Map<String, String> params) withQValue(float qValue) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.pekko.http.impl.util.LazyValueBytesRenderable
render, toString, value, valueBytesMethods inherited from interface org.apache.pekko.http.scaladsl.model.WithQValue
withQValue
-
Constructor Details
-
MediaType
-
-
Method Details
-
applicationBinary
public static MediaType.Binary applicationBinary(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) -
applicationWithFixedCharset
public static MediaType.WithFixedCharset applicationWithFixedCharset(String subType, HttpCharset charset, scala.collection.immutable.Seq<String> fileExtensions) -
applicationWithOpenCharset
public static MediaType.WithOpenCharset applicationWithOpenCharset(String subType, scala.collection.immutable.Seq<String> fileExtensions) -
audio
public static MediaType.Binary audio(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) -
image
public static MediaType.Binary image(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) -
message
public static MediaType.Binary message(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) -
text
public static MediaType.WithOpenCharset text(String subType, scala.collection.immutable.Seq<String> fileExtensions) -
textWithFixedCharset
public static MediaType.WithFixedCharset textWithFixedCharset(String subType, HttpCharset charset, scala.collection.immutable.Seq<String> fileExtensions) -
video
public static MediaType.Binary video(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) -
font
public static MediaType.Binary font(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) -
customBinary
public static MediaType.Binary customBinary(String mainType, String subType, MediaType.Compressibility comp, scala.collection.immutable.List<String> fileExtensions, scala.collection.immutable.Map<String, String> params, boolean allowArbitrarySubtypes) -
customWithFixedCharset
public static MediaType.WithFixedCharset customWithFixedCharset(String mainType, String subType, HttpCharset charset, scala.collection.immutable.List<String> fileExtensions, scala.collection.immutable.Map<String, String> params, boolean allowArbitrarySubtypes) -
customWithOpenCharset
-
customMultipart
public static MediaType.Multipart customMultipart(String subType, scala.collection.immutable.Map<String, String> params) -
custom
public static MediaType custom(String value, boolean binary, MediaType.Compressibility comp, scala.collection.immutable.List<String> fileExtensions) -
parse
public static scala.util.Either<scala.collection.immutable.List<ErrorInfo>,MediaType> parse(String value) Tries to parse aMediaTypevalue from the given String. ReturnsRight(mediaType)if successful andLeft(errors)otherwise.- Parameters:
value- (undocumented)- Returns:
- (undocumented)
-
unapply
-
mainType
Description copied from interface:MediaTypeThe main-type of this media-type. -
subType
Description copied from interface:MediaTypeThe sub-type of this media-type. -
fileExtensions
-
params
-
comp
-
isApplication
public boolean isApplication()- Specified by:
isApplicationin interfaceMediaType
-
isAudio
public boolean isAudio() -
isImage
public boolean isImage() -
isMessage
public boolean isMessage() -
isMultipart
public boolean isMultipart()- Specified by:
isMultipartin interfaceMediaType
-
isText
public boolean isText() -
isVideo
public boolean isVideo() -
withParams
-
withComp
-
withQValue
- Specified by:
withQValuein interfaceWithQValue<MediaRange>
-
equals
-
hashCode
public int hashCode() -
toRange
JAVA API -
toRange
Description copied from interface:MediaTypeCreates a media-range from this media-type with a given qValue. -
isCompressible
public boolean isCompressible()Description copied from interface:MediaTypeTrue when this media-type is generally compressible.- Specified by:
isCompressiblein interfaceMediaType- Returns:
- (undocumented)
-