• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

how to read the HttpRequest twice

 
Ranch Hand
Posts: 165
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


 
Sheriff
Posts: 24632
56
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.
 
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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: 165
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: 24632
56
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: 165
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
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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?
 
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!