Class MediaType
- java.lang.Object
-
- akka.http.scaladsl.model.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
). ThereforeMediaType
instances are frequently encountered as a member of aContentType
, which groups aMediaType
with a potentially requiredHttpCharset
to hold everything required for being able to interpret anHttpEntity
.MediaTypes come in three basic forms:
1. Binary: These do not need an additional
HttpCharset
to be able to form aContentType
. 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 aContentType
.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 aContentType
. The most prominent example is probablyapplication/json
which must always be UTF-8 encoded. Like binary MediaTypesWithFixedCharset
types can be implicitly converted to aContentType
.Not for user extension.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MediaType.Binary
static class
MediaType.Compressibility
static class
MediaType.Compressible$
static class
MediaType.Gzipped$
static class
MediaType.Multipart
static class
MediaType.NonBinary
static class
MediaType.NonMultipartWithOpenCharset
static class
MediaType.NotCompressible$
static class
MediaType.WithFixedCharset
static class
MediaType.WithOpenCharset
-
Constructor Summary
Constructors Constructor Description MediaType(java.lang.String _mainType, java.lang.String _subType)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static MediaType.Binary
applicationBinary(java.lang.String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<java.lang.String> fileExtensions)
static MediaType.WithFixedCharset
applicationWithFixedCharset(java.lang.String subType, HttpCharset charset, scala.collection.immutable.Seq<java.lang.String> fileExtensions)
static MediaType.WithOpenCharset
applicationWithOpenCharset(java.lang.String subType, scala.collection.immutable.Seq<java.lang.String> fileExtensions)
static MediaType.Binary
audio(java.lang.String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<java.lang.String> fileExtensions)
abstract MediaType.Compressibility
comp()
static MediaType
custom(java.lang.String value, boolean binary, MediaType.Compressibility comp, scala.collection.immutable.List<java.lang.String> fileExtensions)
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)
static MediaType.Multipart
customMultipart(java.lang.String subType, scala.collection.immutable.Map<java.lang.String,java.lang.String> params)
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)
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)
boolean
equals(java.lang.Object that)
abstract scala.collection.immutable.List<java.lang.String>
fileExtensions()
static MediaType.Binary
font(java.lang.String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<java.lang.String> fileExtensions)
int
hashCode()
static MediaType.Binary
image(java.lang.String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<java.lang.String> fileExtensions)
boolean
isApplication()
boolean
isAudio()
boolean
isCompressible()
True when this media-type is generally compressible.boolean
isImage()
boolean
isMessage()
boolean
isMultipart()
boolean
isText()
boolean
isVideo()
java.lang.String
mainType()
The main-type of this media-type.static MediaType.Binary
message(java.lang.String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<java.lang.String> fileExtensions)
abstract scala.collection.immutable.Map<java.lang.String,java.lang.String>
params()
static scala.util.Either<scala.collection.immutable.List<ErrorInfo>,MediaType>
parse(java.lang.String value)
Tries to parse aMediaType
value from the given String.java.lang.String
subType()
The sub-type of this media-type.static MediaType.WithOpenCharset
text(java.lang.String subType, scala.collection.immutable.Seq<java.lang.String> fileExtensions)
static MediaType.WithFixedCharset
textWithFixedCharset(java.lang.String subType, HttpCharset charset, scala.collection.immutable.Seq<java.lang.String> fileExtensions)
MediaRange
toRange()
JAVA APIMediaRange
toRange(float qValue)
Creates a media-range from this media-type with a given qValue.static scala.Option<java.lang.String>
unapply(MediaType mediaType)
static MediaType.Binary
video(java.lang.String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<java.lang.String> fileExtensions)
abstract MediaType
withComp(MediaType.Compressibility comp)
abstract MediaType
withParams(scala.collection.immutable.Map<java.lang.String,java.lang.String> params)
MediaRange
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
-
-
-
-
Method Detail
-
applicationBinary
public static MediaType.Binary applicationBinary(java.lang.String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<java.lang.String> fileExtensions)
-
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)
-
audio
public static MediaType.Binary audio(java.lang.String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<java.lang.String> fileExtensions)
-
image
public static MediaType.Binary image(java.lang.String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<java.lang.String> fileExtensions)
-
message
public static MediaType.Binary message(java.lang.String subType, MediaType.Compressibility comp, 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)
-
video
public static MediaType.Binary video(java.lang.String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<java.lang.String> fileExtensions)
-
font
public static MediaType.Binary font(java.lang.String subType, MediaType.Compressibility comp, 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 aMediaType
value from the given String. ReturnsRight(mediaType)
if successful andLeft(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.
-
subType
public java.lang.String subType()
Description copied from interface:MediaType
The sub-type of this media-type.
-
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()
-
comp
public abstract MediaType.Compressibility comp()
-
isApplication
public boolean isApplication()
- Specified by:
isApplication
in interfaceMediaType
-
isMultipart
public boolean isMultipart()
- Specified by:
isMultipart
in interfaceMediaType
-
withParams
public abstract MediaType withParams(scala.collection.immutable.Map<java.lang.String,java.lang.String> params)
-
withComp
public abstract MediaType withComp(MediaType.Compressibility comp)
-
withQValue
public MediaRange withQValue(float qValue)
- Specified by:
withQValue
in interfaceWithQValue<MediaRange>
-
equals
public boolean equals(java.lang.Object that)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toRange
public MediaRange toRange()
JAVA API
-
toRange
public MediaRange toRange(float qValue)
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)
-
-