MultipartUtils { public static boolean isContentTransferEncodingBase64Encoded(final Map<String, List<String>> partHeaders) { String contentEncoding = MultipartUtils.getHeader(CONTENT_TRANSFER_ENCODING, partHeaders); return contentEncoding != null && "base64".equalsIgnoreCase(contentEncoding); } private  MultipartUtils(); static boolean isMultipart(final String contentTypeHeaderValue); static boolean hasMultipartContentType(final Map<String, List<String>> headers); static String getContentType(final Map<String, List<String>> headers); static long getContentLength(final Map<String, List<String>> headers); static String getCharEncoding(final Map<String, List<String>> headers); static List<String> getHeaders(final String headerName, final Map<String, List<String>> headers); static String getHeader(final String headerName, final Map<String, List<String>> headers); static boolean isFormField(final Map<String, List<String>> headers, final MultipartContext context); static String readFormParameterValue(final StreamStorage streamStorage, final Map<String, List<String>> headers); static String getFileName(final Map<String, List<String>> headers); static String getFieldName(final Map<String, List<String>> headers); static boolean isContentTransferEncodingBase64Encoded(final Map<String, List<String>> partHeaders); static byte[] getBoundary(final String contentType); static final byte DASH; static final byte CR; static final byte LF; static final byte[] HEADER_DELIMITER; static final String MULTIPART; static final String CONTENT_DISPOSITION; static final String CONTENT_TRANSFER_ENCODING; static final String CONTENT_LENGTH; static final String CONTENT_TYPE; static final String FORM_DATA; static final String ATTACHMENT; static final String MULTIPART_FORM_DATA; static final String MULTIPART_MIXED; static final String TEXT_PLAIN; }
@Test public void testIsContentTransferEncodingBase64Encoded(){ Map<String, List<String>> base64ContentTransferEncodingHeaders = new HashMap<String, List<String>>(); base64ContentTransferEncodingHeaders.put(MultipartUtils.CONTENT_TRANSFER_ENCODING.toLowerCase(), Collections.singletonList("base64")); assertTrue(MultipartUtils.isContentTransferEncodingBase64Encoded(base64ContentTransferEncodingHeaders)); Map<String, List<String>> base64ContentTransferEncodingHeadersCaseInsensitive = new HashMap<String, List<String>>(); base64ContentTransferEncodingHeadersCaseInsensitive.put(MultipartUtils.CONTENT_TRANSFER_ENCODING.toLowerCase(), Collections.singletonList("bASe64")); assertTrue(MultipartUtils.isContentTransferEncodingBase64Encoded(base64ContentTransferEncodingHeadersCaseInsensitive)); Map<String, List<String>> base64ContentTransferEncodingHeadersEmpty = new HashMap<String, List<String>>(); base64ContentTransferEncodingHeadersEmpty.put(MultipartUtils.CONTENT_TRANSFER_ENCODING.toLowerCase(), Collections.singletonList("")); assertFalse(MultipartUtils.isContentTransferEncodingBase64Encoded(base64ContentTransferEncodingHeadersEmpty)); Map<String, List<String>> base64ContentTransferEncodingHeadersNull = new HashMap<String, List<String>>(); base64ContentTransferEncodingHeadersNull.put(MultipartUtils.CONTENT_TRANSFER_ENCODING.toLowerCase(), null); assertFalse(MultipartUtils.isContentTransferEncodingBase64Encoded(base64ContentTransferEncodingHeadersNull)); Map<String, List<String>> base64ContentTransferEncodingHeadersMissing = new HashMap<String, List<String>>(); base64ContentTransferEncodingHeadersMissing.put(MultipartUtils.CONTENT_TRANSFER_ENCODING.toLowerCase(), null); assertFalse(MultipartUtils.isContentTransferEncodingBase64Encoded(base64ContentTransferEncodingHeadersMissing)); }