My servlet's doPost() receives an HttpServletRequest whose ServletInputStream sends me a large chunk of uuencoded data wrapped in XML. E.g., there is an element:
<filedata encoding="base64">largeChunkEncodedHere</filedata>
I need to decode the chunk and write it to a file. I would like to get an InputStream from the chunk, decode it as a stream using MimeUtility, and use that stream to write the file---I would prefer not to read this large chunk into memory.
The XML is flat; i.e., there is not much nesting. My first idea is to use a SAX parser but I don't know how to do the hand-off to a stream to read just the chunk.
Thanks for your ideas.
Glenn
Edit 1: Note JB Nizet's pessimistic answer in this post.
Edit 2: I've answered my own question affirmatively below, and marked maximdim's answer below as correct, even though it doesn't quite answer the question, it did direct me to the StAX API and Woodstox.
One more suggestion wrt Woodstox: it can also decode that base64 encoded stuff from within, efficiently. To do that, you need to cast XMLStreamReader into XMLStreamReader2 (or TypedXMLStreamReader), which is part of Stax2 extension API.
But with that, you get methods readElementAsBinary() and getElementAsBinary() which automatically handle Base64 decoding. XMLStreamWriter2 similarly has Base64-encoding methods for writing binary data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With