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). ThereforeMediaTypeinstances are frequently encountered as a member of aContentType, which groups aMediaTypewith a potentially requiredHttpCharsetto hold everything required for being able to interpret anHttpEntity.MediaTypes come in three basic forms:
1. Binary: These do not need an additional
HttpCharsetto 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
HttpCharsetinstances 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
HttpCharsetinstances to form aContentType. The most prominent example is probablyapplication/jsonwhich must always be UTF-8 encoded. Like binary MediaTypesWithFixedCharsettypes can be implicitly converted to aContentType.Not for user extension.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMediaType.Binarystatic classMediaType.Compressibilitystatic classMediaType.Compressible$static classMediaType.Gzipped$static classMediaType.Multipartstatic classMediaType.NonBinarystatic classMediaType.NonMultipartWithOpenCharsetstatic classMediaType.NotCompressible$static classMediaType.WithFixedCharsetstatic classMediaType.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.BinaryapplicationBinary(java.lang.String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<java.lang.String> fileExtensions)static MediaType.WithFixedCharsetapplicationWithFixedCharset(java.lang.String subType, HttpCharset charset, scala.collection.immutable.Seq<java.lang.String> fileExtensions)static MediaType.WithOpenCharsetapplicationWithOpenCharset(java.lang.String subType, scala.collection.immutable.Seq<java.lang.String> fileExtensions)static MediaType.Binaryaudio(java.lang.String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<java.lang.String> fileExtensions)abstract MediaType.Compressibilitycomp()static MediaTypecustom(java.lang.String value, boolean binary, MediaType.Compressibility comp, scala.collection.immutable.List<java.lang.String> fileExtensions)static MediaType.BinarycustomBinary(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.MultipartcustomMultipart(java.lang.String subType, scala.collection.immutable.Map<java.lang.String,java.lang.String> params)static MediaType.WithFixedCharsetcustomWithFixedCharset(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.WithOpenCharsetcustomWithOpenCharset(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)booleanequals(java.lang.Object that)abstract scala.collection.immutable.List<java.lang.String>fileExtensions()static MediaType.Binaryfont(java.lang.String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<java.lang.String> fileExtensions)inthashCode()static MediaType.Binaryimage(java.lang.String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<java.lang.String> fileExtensions)booleanisApplication()booleanisAudio()booleanisCompressible()True when this media-type is generally compressible.booleanisImage()booleanisMessage()booleanisMultipart()booleanisText()booleanisVideo()java.lang.StringmainType()The main-type of this media-type.static MediaType.Binarymessage(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 aMediaTypevalue from the given String.java.lang.StringsubType()The sub-type of this media-type.static MediaType.WithOpenCharsettext(java.lang.String subType, scala.collection.immutable.Seq<java.lang.String> fileExtensions)static MediaType.WithFixedCharsettextWithFixedCharset(java.lang.String subType, HttpCharset charset, scala.collection.immutable.Seq<java.lang.String> fileExtensions)MediaRangetoRange()JAVA APIMediaRangetoRange(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.Binaryvideo(java.lang.String subType, MediaType.Compressibility comp, scala.collection.immutable.Seq<java.lang.String> fileExtensions)abstract MediaTypewithComp(MediaType.Compressibility comp)abstract MediaTypewithParams(scala.collection.immutable.Map<java.lang.String,java.lang.String> params)MediaRangewithQValue(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 aMediaTypevalue 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:MediaTypeThe main-type of this media-type.
-
subType
public java.lang.String subType()
Description copied from interface:MediaTypeThe 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:
isApplicationin interfaceMediaType
-
isMultipart
public boolean isMultipart()
- Specified by:
isMultipartin 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:
withQValuein interfaceWithQValue<MediaRange>
-
equals
public boolean equals(java.lang.Object that)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toRange
public MediaRange toRange()
JAVA API
-
toRange
public MediaRange toRange(float qValue)
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)
-
-