• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

multiple calls to ServletRequest.getWriter() ?

 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    IntelliJ IDE Clojure Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks a lot Frits! Thanks for the help!
     
    Heroic work plunger man. Please allow me to introduce you to this tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic