aspose file tools*
The moose likes Servlets and the fly likes how to read the HttpRequest twice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to read the HttpRequest twice" Watch "how to read the HttpRequest twice" New topic
Author

how to read the HttpRequest twice

Ravi Danum
Ranch Hand

Joined: Jan 13, 2009
Posts: 104
Hello,

Is there a way to read a HttpServletRequest inputStream twice?

I have made a deep copy, but in so doing have gone to the end of the stream.

I want to use the apache fileupload code to look for request parameters in the inputStream. Using the apache fileupload requires the request itself to be used as a parameter, so I can't use the copy.

I value your response!

-ravi


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

What you are doing sounds like a bad idea (a deep copy? what for?) but the usual way to read an InputStream twice is to wrap it in a PushbackInputStream with a suitably large buffer size.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

Why aren't you just using one of the 3rd-party packages that handles this for you?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ravi Danum
Ranch Hand

Joined: Jan 13, 2009
Posts: 104

Hello,

I am processing a multipart fileupload request.

The first step is to read one of the request parameters and validate it.

The next step is to write the entire request inputStream to disc.

I am using apache fileupload jar file to get the request parameter from the stream.

So you see I need two passes of the request inputstream to fulfill my requirements.

-ravi
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Ravi Danum wrote:The next step is to write the entire request inputStream to disc.


Why would you want to do that?
Ravi Danum
Ranch Hand

Joined: Jan 13, 2009
Posts: 104

This is the requirement. The file must be in this format to be read by the rest of the system.

Thanks.

-ravi
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

I ask again, why aren't you using one of the popular libraries to handle the multi-part request?
 
Don't get me started about those stupid light bulbs.
 
subject: how to read the HttpRequest twice