use the inputstream to write to a file and to process.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: use the inputstream to write to a file and to process.

Hybrid View

  1. #1
    Quan Ha Guest

    use the inputstream to write to a file and to process.


    Hi
    I have a servlet that uses the HttpServletRequest stream, req.getInputStream(),
    to write to a file and to process data. The way I understand is that once
    you use it the input stream buffer is clear. Is there a way to use one input
    stream to do both tasks?

    Here is the code.

    public class AcceptorWeb extends FWServlet
    {
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws
    ServletException, IOException
    {

    res.setContentType( "text/html" );

    writeToFile( req.getInputStream() );
    acceptFormData( req.getInputStream() );

    }

    public void writeToFile(InputStream is) throws Exception
    {
    }

    public void acceptFormData(InputStream is) throws Exception
    {
    }

    }


  2. #2
    Paul Clapham Guest

    Re: use the inputstream to write to a file and to process.

    processData( req.getInputStream() );

    }

    public void processData(InputStream is)
    {
    // read a line of data
    // write it to the file
    // do whatever acceptFormData does with the line
    // repeat this until you reach the end of the stream
    }


    "Quan Ha" <qha@fedworld.gov> wrote in message
    news:3bf27a2e$1@147.208.176.211...
    >
    > Hi
    > I have a servlet that uses the HttpServletRequest stream,

    req.getInputStream(),
    > to write to a file and to process data. The way I understand is that once
    > you use it the input stream buffer is clear. Is there a way to use one

    input
    > stream to do both tasks?
    >
    > Here is the code.
    >
    > public class AcceptorWeb extends FWServlet
    > {
    > public void doGet(HttpServletRequest req, HttpServletResponse res)

    throws
    > ServletException, IOException
    > {
    >
    > res.setContentType( "text/html" );
    >
    > writeToFile( req.getInputStream() );
    > acceptFormData( req.getInputStream() );
    >
    > }
    >
    > public void writeToFile(InputStream is) throws Exception
    > {
    > }
    >
    > public void acceptFormData(InputStream is) throws Exception
    > {
    > }
    >
    > }
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center