ballerina.mime package
public struct Entity
Represent the headers and body of a message. This can be used to represent both the entity of a top level message and an entity(body part) inside of a multipart entity.
Field Name | Data Type | Description | Default Value |
---|---|---|---|
contentType | MediaType | Describes the data contained in the body of the entity | |
contentId | string | Helps one body of an entity to make a reference to another | |
headers | map | Denote general, request/response and entity related headers. Keys of the header map should represent the header name and value will be the 'HeaderValue' struct | |
textData | string | Contents of the body in string form if the content is of text type | |
jsonData | json | Contents of the body in json form if the content is of json type | |
xmlData | xml | Contents of the body in xml form if the content is of xml type | |
byteData | blob | Contents of the body as a byte array | |
overflowData | File | If the size of the entity exceeds the limit defined in ballerina service or the client connector, contents will be saved in a temporary file and can be accessed through this file handler | |
multipartData | Entity[] | Represent body parts(entities) of a multipart entity | |
size | int | Represent the size of the entity | |
fileName | string | Default filename for storing the bodypart, if the receiving agent wishes to store it in an external file | |
contentDisposition | Disposition | Indicates how the body part should be presented (inline, attachment or as form-data) | |
name | string | Represent the field name in case of 'multipart/form-data' |
public struct MediaType
Describes the nature of the data in the body of a MIME entity.
Field Name | Data Type | Description | Default Value |
---|---|---|---|
primaryType | string | Declares the general type of data | |
subType | string | A specific format of the primary type data | |
suffix | string | Identify the semantics of a specific media type | |
parameters | map | A set of parameters, specified in an attribute=value notation |
-
< MediaType > toString ( ) ( string )
Get ���primaryType/subtype+suffix��� combination in string format.
Return Variable Data Type Description string -
< MediaType > toStringWithParameters ( ) ( string )
Convert the media type to a string suitable for use as the value of a corresponding HTTP header.
Return Variable Data Type Description string
public struct MimeBase64Decoder
Represent MIME specific base64 decoder. This follows RFC 2045 for decoding operation.
-
< MimeBase64Decoder > decode ( blob content ) ( blob )
Decode byte array using MIME Base64 encoding scheme.
Parameter Name Data Type Description content blob the byte array to decode Return Variable Data Type Description blob -
< MimeBase64Decoder > decodeString ( string content , string charset ) ( string )
Decode a given string using MIME Base64 decoding scheme. First the given string will be converted to a byte array with the given charset encoding. If the charset given is null default 'UTF-8' will be used. Then that byte array will be decoded using MIME Base64 decoding scheme and a new string will be constructed with the given charset.
Parameter Name Data Type Description content string string to decode charset string charset used in the given string and the resulting string Return Variable Data Type Description string
public struct MimeBase64Encoder
Represent MIME specific base64 encoder. This follows RFC 2045 for encoding operation.
-
< MimeBase64Encoder > encode ( blob content ) ( blob )
Encode byte array using MIME Base64 encoding scheme.
Parameter Name Data Type Description content blob the byte array to encode Return Variable Data Type Description blob -
< MimeBase64Encoder > encodeString ( string content , string charset ) ( string )
Encode a given string using MIME Base64 encoding scheme. First the given string will be converted to a byte array with the given charset encoding. If the charset given is null default 'UTF-8' will be used. Then that byte array will be encoded using MIME Base64 encoding scheme and a new string will be constructed with the given charset.
Parameter Name Data Type Description content string string to encode charset string charset used in the given string and the resulting string Return Variable Data Type Description string
public struct QuotedPrintableDecoder
Represent quoated-printable decoder.
public struct QuotedPrintableEncoder
Represent quoated-printable encoder.
public function getBlob ( Entity entity ) ( blob )
Given an entity, get the content as a byte array, either from the memory or from the file handler.
Parameter Name | Data Type | Description |
---|---|---|
entity | Entity | Represent mime Entity |
public function getJson ( Entity entity ) ( json )
Given an entity, get the json payload, either from the memory or from the file handler.
Parameter Name | Data Type | Description |
---|---|---|
entity | Entity | Represent mime Entity |
public function getMediaType ( string contentType ) ( MediaType )
Given the Content-Type in string, get the MediaType struct populated with it.
Parameter Name | Data Type | Description |
---|---|---|
contentType | string | Content-Type in string |
public function getText ( Entity entity ) ( string )
Given an entity, get the text payload, either from the memory or from the file handler.
Parameter Name | Data Type | Description |
---|---|---|
entity | Entity | Represent mime Entity |
public function getXml ( Entity entity ) ( xml )
Given an entity, get the xml payload, either from the memory or from the file handler.
Parameter Name | Data Type | Description |
---|---|---|
entity | Entity | Represent mime Entity |
public enum Disposition
Indicates how the body part should be presented.
Name | Description |
---|---|
INLINE | Is intended to be displayed automatically upon display of the message |
ATTACHMENT | Indicate that the body part is separate from the main body of the top level message |
FORM_DATA | When the media type is multipart/form-data, content disposition will be 'form-data' |
APPLICATION_FORM_URLENCODED
Attribute Name | Data Type | Description |
---|---|---|
APPLICATION_FORM_URLENCODED | string | Represent 'application/x-www-form-urlencoded' media type value |
APPLICATION_JSON
Attribute Name | Data Type | Description |
---|---|---|
APPLICATION_JSON | string | Represent 'application/json' media type value |
APPLICATION_OCTET_STREAM
Attribute Name | Data Type | Description |
---|---|---|
APPLICATION_OCTET_STREAM | string | Represent 'application/octet-stream' media type value |
APPLICATION_SVG_XML
Attribute Name | Data Type | Description |
---|---|---|
APPLICATION_SVG_XML | string | Represent 'application/svg+xml' media type value |
APPLICATION_XHTML_XML
Attribute Name | Data Type | Description |
---|---|---|
APPLICATION_XHTML_XML | string | Represent 'application/xhtml+xml' media type value |
APPLICATION_XML
Attribute Name | Data Type | Description |
---|---|---|
APPLICATION_XML | string | Represent 'application/xml' media type value |
MULTIPART_FORM_DATA
Attribute Name | Data Type | Description |
---|---|---|
MULTIPART_FORM_DATA | string | Represent 'multipart/form-data' media type value |
TEXT_HTML
Attribute Name | Data Type | Description |
---|---|---|
TEXT_HTML | string | Represent 'text/html' media type value |
TEXT_PLAIN
Attribute Name | Data Type | Description |
---|---|---|
TEXT_PLAIN | string | Represent 'text/plain' media type value |
TEXT_XML
Attribute Name | Data Type | Description |
---|---|---|
TEXT_XML | string | Represent 'text/xml' media type value |
BOUNDARY
Attribute Name | Data Type | Description |
---|---|---|
BOUNDARY | string | Key name for 'boundary' parameter in MediaType. This is needed for composite type media types |
START
Attribute Name | Data Type | Description |
---|---|---|
START | string | Key name for 'start' parameter in MediaType. This determines which part in the multipart message contains the payload |
TYPE
Attribute Name | Data Type | Description |
---|---|---|
TYPE | string | Key name for 'type' parameter in MediaType. This indicates the MIME media type of the 'root' body part |
CHARSET
Attribute Name | Data Type | Description |
---|---|---|
CHARSET | string | Key name for 'charset' parameter in MediaType. Indicate the character set of the body text |
DEFAULT_CHARSET
Attribute Name | Data Type | Description |
---|---|---|
DEFAULT_CHARSET | string | Default charset to be used with mime encoding and decoding |