public class MultipartUtils extends Object
Utilities to parse a multipart stream.
| Modifier and Type | Field and Description |
|---|---|
static String |
ATTACHMENT
Content disposition attachment parameter
|
static String |
CONTENT_DISPOSITION
Content disposition header name
|
static String |
CONTENT_LENGTH
Content length header name
|
static String |
CONTENT_TRANSFER_ENCODING
Content transfer encoding header name
|
static String |
CONTENT_TYPE
Content type header name
|
static byte |
CR
The (\r) character in bytes
|
static byte |
DASH
The dash (-) character in bytes
|
static String |
FORM_DATA
Content disposition form-data parameter
|
static byte[] |
HEADER_DELIMITER
Sequence of bytes that represents the end of a headers section
|
static byte |
LF
The (\n) character in bytes
|
static String |
MULTIPART
Multipart content type prefix
|
static String |
MULTIPART_FORM_DATA
Specific multipart/form-data content type
|
static String |
MULTIPART_MIXED
Specific multipart/mixed content type
|
static String |
TEXT_PLAIN
text/plain mime-type
|
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
getBoundary(String contentType)
Extracts the boundary parameter value defined in the Content-Type header of a multipart request.
|
static String |
getCharEncoding(Map<String,List<String>> headers)
Extracts the charset parameter value from the content type header.
|
static long |
getContentLength(Map<String,List<String>> headers)
Returns the value of the content length header if present.
|
static String |
getContentType(Map<String,List<String>> headers)
Returns the value of the content type header if present.
|
static String |
getFieldName(Map<String,List<String>> headers)
Returns the 'name' parameter of the Content-disposition header.
|
static String |
getFileName(Map<String,List<String>> headers)
Returns the 'filename' parameter of the Content-disposition header.
|
static String |
getHeader(String headerName,
Map<String,List<String>> headers)
Returns the first value of a particular header
|
static List<String> |
getHeaders(String headerName,
Map<String,List<String>> headers)
Returns the list of values fo a particular header.
|
static boolean |
hasMultipartContentType(Map<String,List<String>> headers)
Checks if the headers contains a Content-Type header that defines a multipart request.
|
static boolean |
isContentTransferEncodingBase64Encoded(Map<String,List<String>> partHeaders)
Returns true if the headers contain the Content-transfer-encoding with value 'base64'.
|
static boolean |
isFormField(Map<String,List<String>> headers,
MultipartContext context)
Checks if the part is a form field.
|
static boolean |
isMultipart(String contentTypeHeaderValue)
Checks if the Content-Type header defines a multipart request.
|
static String |
readFormParameterValue(org.synchronoss.cloud.nio.stream.storage.StreamStorage streamStorage,
Map<String,List<String>> headers)
Reads the form fields into a string.
|
public static final byte DASH
public static final byte CR
public static final byte LF
public static final byte[] HEADER_DELIMITER
public static final String MULTIPART
public static final String CONTENT_DISPOSITION
public static final String CONTENT_TRANSFER_ENCODING
public static final String CONTENT_LENGTH
public static final String CONTENT_TYPE
public static final String FORM_DATA
public static final String ATTACHMENT
public static final String MULTIPART_FORM_DATA
public static final String MULTIPART_MIXED
public static final String TEXT_PLAIN
public static boolean isMultipart(String contentTypeHeaderValue)
Checks if the Content-Type header defines a multipart request.
contentTypeHeaderValue - The value of the Content-Type header.public static boolean hasMultipartContentType(Map<String,List<String>> headers)
Checks if the headers contains a Content-Type header that defines a multipart request.
headers - The headers mappublic static String getContentType(Map<String,List<String>> headers)
Returns the value of the content type header if present.
headers - The headers mappublic static long getContentLength(Map<String,List<String>> headers)
Returns the value of the content length header if present. -1 if the header is not present or if the value cannot be converted to a long
headers - The headers mappublic static String getCharEncoding(Map<String,List<String>> headers)
Extracts the charset parameter value from the content type header.
headers - The headers mappublic static List<String> getHeaders(String headerName, Map<String,List<String>> headers)
Returns the list of values fo a particular header.
headerName - The header nameheaders - The list of headerspublic static String getHeader(String headerName, Map<String,List<String>> headers)
Returns the first value of a particular header
headerName - The header nameheaders - The headerspublic static boolean isFormField(Map<String,List<String>> headers, MultipartContext context)
Checks if the part is a form field. The rules are:
headers - The part headerscontext - The multipart contextpublic static String readFormParameterValue(org.synchronoss.cloud.nio.stream.storage.StreamStorage streamStorage, Map<String,List<String>> headers)
Reads the form fields into a string. The method takes care of handling the char encoding.
If an error occurs while reading the StreamStorage, an IllegalStateException will be thrown.
streamStorage - The stream storage.headers - The part headers.public static String getFileName(Map<String,List<String>> headers)
Returns the 'filename' parameter of the Content-disposition header.
headers - The list of headerspublic static String getFieldName(Map<String,List<String>> headers)
Returns the 'name' parameter of the Content-disposition header.
headers - The list of headerspublic static boolean isContentTransferEncodingBase64Encoded(Map<String,List<String>> partHeaders)
Returns true if the headers contain the Content-transfer-encoding with value 'base64'.
partHeaders - The list of headerspublic static byte[] getBoundary(String contentType)
Extracts the boundary parameter value defined in the Content-Type header of a multipart request.
For example if the Content-Type header is
Content-Type: multipart/form-data; boundary=---------------------------735323031399963166993862150
This method will extract
---------------------------735323031399963166993862150
and return the correspondent bytes.
The charset used to encode the string into bytes is ISO-8859-1 and if it is not supported it will fall back to the default charset.
contentType - The value of the Content-Type header.null if not defined.Copyright © 2017. All rights reserved.