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 class
static class
static class
static class
static final class
static class
static class
static class
static class
static class
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MediaType.Binary
applicationBinary
(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) static MediaType.WithFixedCharset
applicationWithFixedCharset
(String subType, HttpCharset charset, scala.collection.immutable.Seq<String> fileExtensions) static MediaType.WithOpenCharset
applicationWithOpenCharset
(String subType, scala.collection.immutable.Seq<String> fileExtensions) static MediaType.Binary
audio
(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) abstract MediaType.Compressibility
comp()
static MediaType
custom
(String value, boolean binary, MediaType.Compressibility comp, scala.collection.immutable.List<String> fileExtensions) 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) static MediaType.Multipart
customMultipart
(String subType, scala.collection.immutable.Map<String, String> params) 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) static MediaType.WithOpenCharset
customWithOpenCharset
(String mainType, String subType, scala.collection.immutable.List<String> fileExtensions, scala.collection.immutable.Map<String, String> params, boolean allowArbitrarySubtypes) boolean
abstract scala.collection.immutable.List<String>
static MediaType.Binary
font
(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) int
hashCode()
static MediaType.Binary
image
(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) boolean
boolean
isAudio()
boolean
True when this media-type is generally compressible.boolean
isImage()
boolean
boolean
boolean
isText()
boolean
isVideo()
mainType()
The main-type of this media-type.static MediaType.Binary
message
(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) params()
Tries to parse aMediaType
value from the given String.subType()
The sub-type of this media-type.static MediaType.WithOpenCharset
static MediaType.WithFixedCharset
textWithFixedCharset
(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.Binary
video
(String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<String> fileExtensions) abstract MediaType
abstract MediaType
withParams
(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, wait
Methods inherited from interface akka.http.impl.util.LazyValueBytesRenderable
render, toString, value, valueBytes
Methods inherited from interface akka.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 aMediaType
value from the given String. ReturnsRight(mediaType)
if successful andLeft(errors)
otherwise.- Parameters:
value
- (undocumented)- Returns:
- (undocumented)
-
unapply
-
mainType
Description copied from interface:MediaType
The main-type of this media-type. -
subType
Description copied from interface:MediaType
The sub-type of this media-type. -
fileExtensions
-
params
-
comp
-
isApplication
public boolean isApplication()- Specified by:
isApplication
in interfaceMediaType
-
isAudio
public boolean isAudio() -
isImage
public boolean isImage() -
isMessage
public boolean isMessage() -
isMultipart
public boolean isMultipart()- Specified by:
isMultipart
in interfaceMediaType
-
isText
public boolean isText() -
isVideo
public boolean isVideo() -
withParams
-
withComp
-
withQValue
- Specified by:
withQValue
in interfaceWithQValue<MediaRange>
-
equals
-
hashCode
public int hashCode() -
toRange
JAVA API -
toRange
Description copied from interface:MediaType
Creates a media-range from this media-type with a given qValue. -
isCompressible
public boolean isCompressible()Description copied from interface:MediaType
True when this media-type is generally compressible.- Specified by:
isCompressible
in interfaceMediaType
- Returns:
- (undocumented)
-