ballerina/mime

Overview

This module provides a set of APIs to work with messages, which follow the Multipurpose Internet Mail Extensions (MIME) specification as specified in the RFC 2045 standard.

1Entity refers to the header fields and the content of a message or a part of the body in a multipart entity.

Supported multipart types

The module supports multipart/form-data, multipart/mixed, multipart/alternative, multipart/related, and multipart/parallel as multipart content types.

Modify and retrieve the data in an entity

This module provides functions to set and get an entity body from different kinds of message types such as XML, text, JSON, byte[], and body parts. Headers can be modified through functions such as addHeader(), setHeader(), removeHeader(), etc.

Handling large files

The entity object method setFileAsEntityBody() can be used to set large files as the entity body and is able to read it as a stream using the getByteStream() function.

Functions

[6]

base64Decode

Decodes a given input with MIME specific Base64 encoding scheme.

base64DecodeBlob

Decodes a given byte[] using the Base64 encoding scheme.

base64Encode

Encodes a given input with MIME specific Base64 encoding scheme.

base64EncodeBlob

Encodes a given byte[] using the Base64 encoding scheme.

getContentDispositionObject

Given the Content-Disposition as a string, gets the ContentDisposition object with it.

getMediaType

Gets the MediaType object populated with it when the Content-Type is in string.

Classes

[3]

ContentDisposition

Represents values in Content-Disposition header.

Entity

Represents the headers and body of a message.

MediaType

Describes the nature of the data in the body of a MIME entity.

Constants

[28]

APPLICATION_FORM_URLENCODED

Represents the application/x-www-form-urlencoded media type.

APPLICATION_JSON

Represents the application/json media type.

APPLICATION_OCTET_STREAM

Represents the application/octet-stream media type.

APPLICATION_PDF

Represents the application/pdf media type.

APPLICATION_SOAP_XML

Represents the application/soap+xml media type.

APPLICATION_SVG_XML

Represents the application/svg+xml media type.

APPLICATION_XHTML_XML

Represents the application/xhtml+xml media type.

APPLICATION_XML

Represents the application/xml media type.

BOUNDARY

Key name for boundary parameter in MediaType.

CHARSET

Key name for charset parameter in MediaType.

CONTENT_DISPOSITION

Represents content-disposition header name.

CONTENT_ID

Represents content-id header name.

CONTENT_LENGTH

Represents content-length header name.

CONTENT_TYPE

Represents content-type header name.

DEFAULT_CHARSET

Default charset to be used with MIME encoding and decoding.

IMAGE_GIF

Represents the image/gif media type.

IMAGE_JPEG

Represents the image/jpeg media type.

IMAGE_PNG

Represents the image/png media type.

MULTIPART_ALTERNATIVE

Represents the multipart/alternative media type.

MULTIPART_FORM_DATA

Represents the multipart/form-data media type.

MULTIPART_MIXED

Represents the multipart/mixed media type.

MULTIPART_PARALLEL

Represents the multipart/parallel media type.

Represents the multipart/related media type.

START

Key name for start parameter in MediaType.

TEXT_HTML

Represents the text/html media type.

TEXT_PLAIN

Represents the text/plain media type.

TEXT_XML

Represents the text/xml media type.

TYPE

Key name for type parameter in MediaType.

Errors

[16]

DecodeError

Represents a DecodeError with the message and the cause.

EncodeError

Represents an EncodeError with the message and the cause.

Error

Defines the common error type for the module.

GenericMimeError

Represents a GenericMimeError with the message and the cause.

HeaderNotFoundError

Represents a HeaderNotFoundError error with the message and the cause.

HeaderUnavailableError

Represents a HeaderUnavailableError with the message and the cause.

IdleTimeoutTriggeredError

Represents an IdleTimeoutTriggeredError with the message and the cause.

InvalidContentLengthError

Represents a InvalidContentLengthError error with the message and the cause.

InvalidContentTypeError

Represents an InvalidContentTypeError with the message and the cause.

InvalidHeaderOperationError

Represents a InvalidHeaderOperationError error with the message and the cause.

InvalidHeaderParamError

Represents a InvalidHeaderParamError error with the message and the cause.

InvalidHeaderValueError

Represents a InvalidHeaderValueError error with the message and the cause.

NoContentError

Represents a NoContentError with the message and the cause.

ParserError

Represents a ParserError with the message and the cause.

SerializationError

Represents a SerializationError error with the message and the cause.

SetHeaderError

Represents a SetHeaderError with the message and the cause.