This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiple calls to ServletRequest.getWriter() ?

 
Andy Jung
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

when calling getWriter() following a call to getOutputStream() on a ServletRequest and vice versa results in an IllegalStateException.
1. What happens, if multiple calls are made to either getWriter() or getOutputStream? Same behaviour?
2. In case calling getWriter() multiple times doesn't throw a RuntimeException, are the returned references identical or different?

Kind regards,
Andy
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2275
81
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andy,

when calling getWriter() following a call to getOutputStream() on a ServletRequest

ok, you mean ServletResponse object (ServletRequest has a getReader() and a getInputStream())

1. What happens, if multiple calls are made to either getWriter() or getOutputStream? Same behaviour?

It will just work, as long as you don't mix them
2. In case calling getWriter() multiple times doesn't throw a RuntimeException, are the returned references identical or different?

They should refer to the same object

Regards,
Frits
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frits! Why do they fail, if mixed?

Thanks!
 
Andy Jung
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, thanks Frits, so I conclude that the following statement always evaluates to true:

and the same is with getInputStream(), getWriter(), getOutputStream()
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2275
81
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Abimaran,
Why do they fail, if mixed?

It has to do with the characteristics of the underlying stream:
  • Input/Output Stream classes are used for binary data
  • Reader/Writer classes are used for character based data


  • You either read/write binary data or characters.

    Regards,
    Frits
     
    Abimaran Kugathasan
    Ranch Hand
    Posts: 2066
    Clojure IntelliJ IDE Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks a lot Frits! Thanks for the help!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic