bayou.io has a generic MultipartParser
You may need adapters to work with it, since it has its own Async and ByteSource interfaces.
The following example shows how to use a parser synchronously with an InputStream
String msg = "" //+ "preamble\r\n" +"--boundary\r\n" +"Head1: Value1\r\n" +"Head2: Value2\r\n" +"\r\n" +"body.body.body.body." +"\r\n--boundary\r\n" +"Head1: Value1\r\n" +"Head2: Value2\r\n" +"\r\n" +"body.body.body.body." +"\r\n--boundary--" + "epilogue"; InputStream is = new ByteArrayInputStream(msg.getBytes("ISO-8859-1")); ByteSource byteSource = new InputStream2ByteSource(is, 1024); MultipartParser parser = new MultipartParser(byteSource, "boundary"); while(true) { try { MultipartPart part = parser.getNextPart().sync(); // async -> sync System.out.println("== part =="); System.out.println(part.headers()); ByteSource body = part.body(); InputStream stream = new ByteSource2InputStream(body, Duration.ofSeconds(1)); drain(stream); } catch (End end) // control exception from getNextPart() { System.out.println("== end of parts =="); break; } }
source share