DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

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
    > {
    > }
    >
    > }
    >




Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links