ContentType

class ContentType : HeaderValueWithParameters

Represents a value for a Content-Type header.

Types

Application

object Application

Provides a list of standard subtypes of an application content type.

Audio

object Audio

Provides a list of standard subtypes of an audio content type.

Image

object Image

Provides a list of standard subtypes of an image content type.

Message

object Message

Provides a list of standard subtypes of a message content type.

MultiPart

object MultiPart

Provides a list of standard subtypes of a multipart content type.

Text

object Text

Provides a list of standard subtypes of a text content type.

Video

object Video

Provides a list of standard subtypes of a video content type.

Constructors

<init>

ContentType(
    contentType: String,
    contentSubtype: String,
    parameters: List<HeaderValueParam> = emptyList())

Properties

contentSubtype

val contentSubtype: String

represents a subtype part of the media type.

contentType

val contentType: String

represents a type part of the media type.

Inherited Properties

content

val content: String

header’s content without parameters

parameters

val parameters: List<HeaderValueParam>

Functions

equals

fun equals(other: Any?): Boolean

hashCode

fun hashCode(): Int

match

fun match(pattern: ContentType): Boolean
fun match(pattern: String): Boolean

Checks if this type matches a pattern type taking into account placeholder symbols * and parameters.

withParameter

fun withParameter(name: String, value: String): ContentType

Creates a copy of this type with the added parameter with the name and value.

withoutParameters

fun withoutParameters(): ContentType

Creates a copy of this type without any parameters

Inherited Functions

parameter

fun parameter(name: String): String?

The first value for the parameter with name comparing case-insensitively or null if no such parameters found

toString

open fun toString(): String

Companion Object Properties

Any

val Any: ContentType

Represents a pattern * / * to match any content type.

Companion Object Functions

parse

fun parse(value: String): ContentType

Parses a string representing a Content-Type header into a ContentType instance.

Extension Functions

charset

fun HeaderValueWithParameters.charset(): Charset?

Extracts a Charset value from the given Content-Type, Content-Disposition or similar header value.

fileExtensions

fun ContentType.fileExtensions(): List<String>

Recommended file name extensions for this content type

withCharset

fun ContentType.withCharset(charset: Charset): ContentType

Creates a copy of this type with the added charset parameter with charset value.

Companion Object Extension Functions

defaultForFile

fun ContentType.Companion.defaultForFile(
    file: File
): ContentType
fun ContentType.Companion.defaultForFile(
    file: Path
): ContentType

defaultForFileExtension

fun ContentType.Companion.defaultForFileExtension(
    extension: String
): ContentType

Default ContentType for extension

defaultForFilePath

fun ContentType.Companion.defaultForFilePath(
    path: String
): ContentType

Default ContentType for file path

fromFileExtension

fun ContentType.Companion.fromFileExtension(
    ext: String
): List<ContentType>

Recommended content type by file name extension

fromFilePath

fun ContentType.Companion.fromFilePath(
    path: String
): List<ContentType>

Recommended content types by file path