Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7528663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:26:38+00:00 2026-05-30T04:26:38+00:00

My servlet’s doPost() receives an HttpServletRequest whose ServletInputStream sends me a large chunk of

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:26:39+00:00Added an answer on May 30, 2026 at 4:26 am

    You could use SAX filter or XPath to get only element(s) you’re interested in. Once you have content of your element, pass it to MimeUtility.decode() and write stream to file.

    I suggest you update your question with code sample and let us know what doesn’t work.

    Update:

    Here is sample code using StaX2 parser (Woodstox). For some reason StaX parser included in JDK doesn’t seems to have comparable getText() method, at least at quick glance.

    Obviously input (r) and output (w) could be any Reader/Writer or Stream – using String just for example here.

        Reader r = new StringReader("<foo><filedata encoding=\"base64\">largeChunkEncodedHere</filedata></foo>");
        Writer w = new StringWriter();
    
        XMLInputFactory2 xmlif = (XMLInputFactory2)XMLInputFactory2.newInstance();
        XMLStreamReader2 sr = (XMLStreamReader2)xmlif.createXMLStreamReader(r);
    
        boolean flag = false;
        while (sr.hasNext()) {
            sr.next();
            if (sr.getEventType() == XMLStreamConstants.START_ELEMENT) {
                if ("filedata".equals(sr.getLocalName())) {
                    flag = true;
                }
            }
            else if (sr.getEventType() == XMLStreamConstants.CHARACTERS) {
                if (flag) {
                    sr.getText(w, false);
                    break;
                }
            }
        }
        System.out.println(w);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Servlet, I can do the following to process binary stream: public void doPost(HttpServletRequest
I have a Java servlet which generates XML, translates it with an XSLT stylesheet,
This [servlet or jsp] must return an XML document [for future processing by my
In a spring servlet xml file, I'm using org.springframework.scheduling.quartz.SchedulerFactoryBean to regularly fire a set
I have a simple (Servlet, JSP, and JSTL) web app whose main functionality is
Servlet is also java program but there is no main method in servlet.Who will
The servlet queries the database and throws data in to a file. This data
javax.servlet.ServletException: Error creating bean with name 'userService' defined in class path resource [applicationContext.xml]: Cannot
A servlet class handles the incoming request object, fetch data & store into StringBuilder/StringBuffer
I have a servlet which reads BINARY file and sends it to a client.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.