• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to read the HttpRequest twice

 
Ravi Danum
Ranch Hand
Posts: 152
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why aren't you just using one of the 3rd-party packages that handles this for you?
 
Ravi Danum
Ranch Hand
Posts: 152
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 152
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ask again, why aren't you using one of the popular libraries to handle the multi-part request?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic