MultipartParser { public Map<String, byte[]> parse(HttpRequest request) { return parse(request.getHeader("Content-Type"), request.getData(), request.getUri()); }  Map<String, byte[]> parse(HttpRequest request); Map<String, byte[]> parse(String contentTypeHeader, InputStream data, URI uri);  }
@Test public void multipartParserTest() throws URISyntaxException { String data = "Content-Type: multipart/form-data; boundary=AaB03x\r\n" + "\r\n" + "--AaB03x\r\n" + "Content-Disposition: form-data; name=\"submit-name\"\r\n" + "\r\n" + "Larry\r\n" + "--AaB03x\r\n" + "Content-Disposition: form-data; name=\"submit-address\"\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "House 1\r\n" + "--AaB03x\r\n" + "Content-Disposition: form-data; name=\"files\"; filename=\"file1.txt\"\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "... contents of file1.txt ...\r\n" + "--AaB03x--\r\n"; ByteArrayInputStream dataStream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); HttpRequest request = HttpRequest.createRequest(new MockCurrentContainer(), new URI("http: com.yahoo.jdisc.http.HttpRequest.Method.POST, dataStream); request.getJDiscRequest().headers().put("Content-Type", "multipart/form-data; boundary=AaB03x"); Map<String, byte[]> parts = new MultipartParser().parse(request); assertEquals(3, parts.size()); assertTrue(parts.containsKey("submit-name")); assertTrue(parts.containsKey("submit-address")); assertTrue(parts.containsKey("files")); assertEquals("Larry", new String(parts.get("submit-name"), StandardCharsets.UTF_8)); assertEquals("... contents of file1.txt ...", new String(parts.get("files"), StandardCharsets.UTF_8)); }