@Test public void testFileUpload() throws IOException { final Multipart form = new Multipart(); form.param("a", "b"); form.param("myfile", "config.properties", new FileInputStream("src/test/resources/config.properties")); final InputStream inputStream = MultipartUtils.serializeMultipartForm(form); final List<Part> parts = new ArrayList<>(Multipart.read(form.getContentType(), -1, inputStream).getParts()); assertEquals(2, parts.size()); assertEquals("a", parts.get(0).getName()); assertEquals("b", IOUtils.toString(parts.get(0).getInputStream(), StandardCharsets.UTF_8)); assertEquals("myfile", parts.get(1).getName()); assertEquals("a=b\n", IOUtils.toString(parts.get(1).getInputStream(), StandardCharsets.UTF_8)); }
public static InputStream serializeMultipartForm(final Multipart form) throws IOException { try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { serializeMultipartForm(form, outputStream); return new ByteArrayInputStream(outputStream.toByteArray()); } }
MultipartUtils { public static InputStream serializeMultipartForm(final Multipart form) throws IOException { try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { serializeMultipartForm(form, outputStream); return new ByteArrayInputStream(outputStream.toByteArray()); } } }
MultipartUtils { public static InputStream serializeMultipartForm(final Multipart form) throws IOException { try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { serializeMultipartForm(form, outputStream); return new ByteArrayInputStream(outputStream.toByteArray()); } } MultipartUtils(); }
MultipartUtils { public static InputStream serializeMultipartForm(final Multipart form) throws IOException { try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { serializeMultipartForm(form, outputStream); return new ByteArrayInputStream(outputStream.toByteArray()); } } MultipartUtils(); static InputStream serializeMultipartForm(final Multipart form); static void serializeMultipartForm(final Multipart form, final OutputStream outputStream); }
MultipartUtils { public static InputStream serializeMultipartForm(final Multipart form) throws IOException { try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { serializeMultipartForm(form, outputStream); return new ByteArrayInputStream(outputStream.toByteArray()); } } MultipartUtils(); static InputStream serializeMultipartForm(final Multipart form); static void serializeMultipartForm(final Multipart form, final OutputStream outputStream);  }