public class MimeUtil extends Object
Constructor and Description |
---|
MimeUtil() |
Modifier and Type | Method and Description |
---|---|
static StringBuilder |
convertDispositionObjectToString(StringBuilder dispositionBuilder,
BMap<String,BValue> contentDispositionStruct) |
static BError |
createError(Context context,
String errMsg)
Create mime specific error record with '{ballerina/mime}MIMEError' as error code.
|
static BError |
createError(Context context,
String reason,
String errMsg)
Create mime specific error record.
|
static boolean |
generateAsJSON(BValue value,
BMap<String,BValue> entityRecord)
Check whether a given value should be serialized specifically as a JSON.
|
static String |
getBaseType(BMap<String,BValue> entity)
Given a ballerina entity, get the content-type as a base type.
|
static byte[] |
getByteArray(InputStream input)
Given an input stream, get a byte array.
|
static String |
getContentDisposition(BMap<String,BValue> entity)
Given a ballerina entity, build the content-disposition header value from 'ContentDisposition' object.
|
static String |
getContentTypeParamValue(String contentType,
String parameterName)
Get parameter value from the content-type header.
|
static String |
getContentTypeWithParameters(BMap<String,BValue> entity)
Given a ballerina entity, get the content-type with parameters included.
|
static BString |
getMessageAsString(BValue dataSource) |
static String |
getNewMultipartDelimiter()
Get a new multipart boundary delimiter.
|
static String |
includeQuotes(String textValue)
Surround the given value with quotes.
|
static boolean |
isJSONCompatible(BType type) |
static boolean |
isJSONContentType(BMap<String,BValue> entityStruct) |
static boolean |
isNotNullAndEmpty(String textValue)
Check whether the given string is not null and empty.
|
static BMap<String,BValue> |
parseMediaType(BMap<String,BValue> mediaType,
String contentType)
Parse 'MediaType' struct with the given Content-Type.
|
static void |
populateContentDispositionObject(BMap<String,BValue> contentDisposition,
String contentDispositionHeaderWithParams) |
static void |
setContentDisposition(BMap<String,BValue> contentDisposition,
BMap<String,BValue> bodyPart,
String contentDispositionHeaderWithParams)
Populate ContentDisposition struct and set it to body part.
|
static void |
setContentLength(BMap<String,BValue> entityStruct,
long length)
Populate given 'Entity' with it's body size.
|
static void |
setContentType(BMap<String,BValue> mediaType,
BMap<String,BValue> entityStruct,
String contentType)
Construct 'MediaType' struct with the given Content-Type and set it into the given 'Entity'.
|
static void |
setMediaTypeToEntity(Context context,
BMap<String,BValue> entityStruct,
String contentType) |
static String |
validateContentType(String contentType) |
static void |
writeInputToOutputStream(InputStream inputStream,
OutputStream outputStream)
Write a given inputstream to a given outputstream.
|
public static String getBaseType(BMap<String,BValue> entity)
entity
- Represent an 'Entity'public static String getContentTypeWithParameters(BMap<String,BValue> entity)
entity
- Represent an 'Entity'public static String getContentTypeParamValue(String contentType, String parameterName)
contentType
- Content-Type value as a stringparameterName
- Name of the parameterpublic static void setContentType(BMap<String,BValue> mediaType, BMap<String,BValue> entityStruct, String contentType)
mediaType
- Represent 'MediaType' structentityStruct
- Represent 'Entity' structcontentType
- Content-Type value in stringpublic static BMap<String,BValue> parseMediaType(BMap<String,BValue> mediaType, String contentType)
mediaType
- Represent 'MediaType' structcontentType
- Content-Type value in stringpublic static void setMediaTypeToEntity(Context context, BMap<String,BValue> entityStruct, String contentType)
public static void setContentDisposition(BMap<String,BValue> contentDisposition, BMap<String,BValue> bodyPart, String contentDispositionHeaderWithParams)
contentDisposition
- Represent the ContentDisposition struct that needs to be filledbodyPart
- Represent a body partcontentDispositionHeaderWithParams
- Represent Content-Disposition header value with parameterspublic static void populateContentDispositionObject(BMap<String,BValue> contentDisposition, String contentDispositionHeaderWithParams)
public static String getContentDisposition(BMap<String,BValue> entity)
entity
- Represent an 'Entity'public static StringBuilder convertDispositionObjectToString(StringBuilder dispositionBuilder, BMap<String,BValue> contentDispositionStruct)
public static void setContentLength(BMap<String,BValue> entityStruct, long length)
entityStruct
- Represent 'Entity'length
- Size of the entity bodypublic static void writeInputToOutputStream(InputStream inputStream, OutputStream outputStream) throws IOException
outputStream
- Represent the outputstream that the inputstream should be written toinputStream
- Represent the inputstream that that needs to be written to outputstreamIOException
- When an error occurs while writing inputstream to outputstreampublic static byte[] getByteArray(InputStream input) throws IOException
input
- Represent an input streamIOException
- In case an error occurs while reading input streampublic static boolean isNotNullAndEmpty(String textValue)
textValue
- Represent a text valuepublic static String includeQuotes(String textValue)
textValue
- Represent a text valuepublic static String getNewMultipartDelimiter()
public static BError createError(Context context, String errMsg)
context
- Represent ballerina contexterrMsg
- Actual error messagepublic static BError createError(Context context, String reason, String errMsg)
context
- Represent ballerina contextreason
- Error code in string formerrMsg
- Actual error messagepublic static boolean isJSONCompatible(BType type)
public static boolean generateAsJSON(BValue value, BMap<String,BValue> entityRecord)
value
- Value to serializeentityRecord
- Entity recordpublic static String validateContentType(String contentType) throws MimeTypeParseException
MimeTypeParseException
Copyright © 2019 WSO2. All rights reserved.