@Test public void transferToShouldWriteStringPart() throws IOException, URISyntaxException { String text = FileUtils.readFileToString(TestUtils.resourceAsFile("test_sample_message.eml"), UTF_8); List<Part> parts = new ArrayList<>(); parts.add(new StringPart("test_sample_message.eml", text)); HttpHeaders headers = new DefaultHttpHeaders(); headers.set( "Cookie", "open-xchange-public-session-d41d8cd98f00b204e9800998ecf8427e=bfb98150b24f42bd844fc9ef2a9eaad5; open-xchange-secret-TSlq4Cm4nCBnDpBL1Px2A=9a49b76083e34c5ba2ef5c47362313fd; JSESSIONID=6883138728830405130.OX2"); headers.set("Content-Length", "9241"); headers.set("Content-Type", "multipart/form-data; boundary=5gigAKQyqDCVdlZ1fCkeLlEDDauTNoOOEhRnFg"); headers.set("Host", "appsuite.qa.open-xchange.com"); headers.set("Accept", "*/*"); String boundary = "uwyqQolZaSmme019O2kFKvAeHoC14Npp"; List<MultipartPart<? extends Part>> multipartParts = MultipartUtils.generateMultipartParts(parts, boundary.getBytes()); try (MultipartBody multipartBody = new MultipartBody(multipartParts, "multipart/form-data; boundary=" + boundary, boundary.getBytes())) { ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer(8 * 1024); multipartBody.transferTo(byteBuf); try { byteBuf.toString(StandardCharsets.UTF_8); } finally { byteBuf.release(); } } }
public long transferTo(ByteBuf target) throws IOException { switch (state) { case DONE: return 0L; case PRE_CONTENT: return transfer(lazyLoadPreContentBuffer(), target, MultipartState.CONTENT); case CONTENT: return transferContentTo(target); case POST_CONTENT: return transfer(lazyLoadPostContentBuffer(), target, MultipartState.DONE); default: throw new IllegalStateException("Unknown state " + state); } }
MultipartPart implements Closeable { public long transferTo(ByteBuf target) throws IOException { switch (state) { case DONE: return 0L; case PRE_CONTENT: return transfer(lazyLoadPreContentBuffer(), target, MultipartState.CONTENT); case CONTENT: return transferContentTo(target); case POST_CONTENT: return transfer(lazyLoadPostContentBuffer(), target, MultipartState.DONE); default: throw new IllegalStateException("Unknown state " + state); } } }
MultipartPart implements Closeable { public long transferTo(ByteBuf target) throws IOException { switch (state) { case DONE: return 0L; case PRE_CONTENT: return transfer(lazyLoadPreContentBuffer(), target, MultipartState.CONTENT); case CONTENT: return transferContentTo(target); case POST_CONTENT: return transfer(lazyLoadPostContentBuffer(), target, MultipartState.DONE); default: throw new IllegalStateException("Unknown state " + state); } } MultipartPart(T part, byte[] boundary); }
MultipartPart implements Closeable { public long transferTo(ByteBuf target) throws IOException { switch (state) { case DONE: return 0L; case PRE_CONTENT: return transfer(lazyLoadPreContentBuffer(), target, MultipartState.CONTENT); case CONTENT: return transferContentTo(target); case POST_CONTENT: return transfer(lazyLoadPostContentBuffer(), target, MultipartState.DONE); default: throw new IllegalStateException("Unknown state " + state); } } MultipartPart(T part, byte[] boundary); long length(); MultipartState getState(); boolean isTargetSlow(); long transferTo(ByteBuf target); long transferTo(WritableByteChannel target); @Override void close(); }
MultipartPart implements Closeable { public long transferTo(ByteBuf target) throws IOException { switch (state) { case DONE: return 0L; case PRE_CONTENT: return transfer(lazyLoadPreContentBuffer(), target, MultipartState.CONTENT); case CONTENT: return transferContentTo(target); case POST_CONTENT: return transfer(lazyLoadPostContentBuffer(), target, MultipartState.DONE); default: throw new IllegalStateException("Unknown state " + state); } } MultipartPart(T part, byte[] boundary); long length(); MultipartState getState(); boolean isTargetSlow(); long transferTo(ByteBuf target); long transferTo(WritableByteChannel target); @Override void close();  }