BatchParserCommon { public static String getBoundary(final String contentType, final int line) throws BatchDeserializerException { final ContentType type = parseContentType(contentType, ContentType.MULTIPART_MIXED, line); final String boundary = type.getParameter(BOUNDARY); if (boundary == null) { throw new BatchDeserializerException("Missing boundary.", BatchDeserializerException.MessageKeys.MISSING_BOUNDARY_DELIMITER, Integer.toString(line)); } final Matcher matcher = PATTERN_BOUNDARY.matcher(boundary); if (matcher.matches()) { return matcher.group(1) == null ? matcher.group(2) : matcher.group(1); } else { throw new BatchDeserializerException("Invalid boundary format", BatchDeserializerException.MessageKeys.INVALID_BOUNDARY, Integer.toString(line)); } } private  BatchParserCommon(); static String getBoundary(final String contentType, final int line); static ContentType parseContentType(final String contentType, final ContentType expected, final int line); static List<List<Line>> splitMessageByBoundary(final List<Line> message, final String boundary); static Line removeEndingCRLF(final Line line); static Header consumeHeaders(final List<Line> remainingMessage); static void consumeBlankLine(final List<Line> remainingMessage, final boolean isStrict); static InputStream convertLineListToInputStream(final List<Line> messageList, final Charset charset); static String trimLineListToLength(final List<Line> list, final int length); static InputStream convertLineListToInputStream(final List<Line> list, final Charset charset,
      final int length); static final String CONTENT_TRANSFER_ENCODING; static final String BINARY_ENCODING; }
@Test public void boundaryParameter() throws Exception { final String boundary = "boundary"; final String contentType = MULTIPART_MIXED + "; boundary=" + boundary + " "; Assert.assertEquals(boundary, BatchParserCommon.getBoundary(contentType, 0)); }
@Test public void boundaryParameterWithQuotes() throws Exception { final String boundary = "batch_1.2+34:2j)0?"; final String contentType = MULTIPART_MIXED + "; boundary=\"" + boundary + "\""; Assert.assertEquals(boundary, BatchParserCommon.getBoundary(contentType, 0)); }
@Test public void boundaryParameterWithSpaces() throws Exception { final String boundary = " boundary"; final String contentType = MULTIPART_MIXED + "; boundary=\"" + boundary + "\" "; Assert.assertEquals(boundary, BatchParserCommon.getBoundary(contentType, 0)); }
@Test public void contentTypeCharset() throws Exception { final String contentType = MULTIPART_MIXED + "; charset=UTF-8;boundary=" + BatchParserCommon.BOUNDARY; final String boundary = BatchParserCommon.getBoundary(contentType, 0); Assert.assertEquals(BatchParserCommon.BOUNDARY, boundary); }