Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request.getInputStream()

 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can anyone please tell me the exact use of request.getInputStream(). Some info is present in HFSJ pg 123, but i am not getting it .....
 
Ranil Liyana Arachchige
Ranch Hand
Posts: 71
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mann,

To understand the request.getInputStream(),response.getOutputStream() think about the following analogy.

suppose there is a tank half filled with water and two pipes are connected to the tank on either side of it.





tank is analogous to the server , pipe A is analogous to the request object and pipe B is analogous to the response object. inputstream carries any incoming bites while outputstream carries any outgoing bites. For an example if you are sending any data from your browser (file upload) to the server that data must be carried up to the server by some carrier. That carrier would be the request object while what ever it carries with it could be obtained by using the inputstream. In the case of anything sent out would be carried by the response object and to stuff the response object with what you want to send outside you need to get response object's outputstream.

Hope this would help you in understanding the concept

Regards,
Ranil

[ October 05, 2008: Message edited by: Ranil Liyana Arachchige ]
[ October 05, 2008: Message edited by: Ranil Liyana Arachchige ]
 
Manoj Shyamm Kumar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a good one Ranil

- servletRequest.getInputStream():ServletInputStream - reads the body of the request as "Binary data" - So its primitive but can be useful when reading POST requests that has large amount of data.

Whereas there is one more way to read the request body, thats:
- servletRequest.getReader(): BufferedReader - reads the body of the request as "Character data". So, obviously it wraps the input stream with more user-friendly, rather character friendly methods.

Dont forget that using both the above methods to read your request may lead to a fatal exception

Hope this helps...
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks manoj....

thanks ranil....it was very gud explanation......
 
Ranil Liyana Arachchige
Ranch Hand
Posts: 71
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

No problem my friend, and thank Manoj for the added clarification too

Regards,
Ranil
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic