Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

binary and text data

 
anarkali perera
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)if i neeed text data can i use both response.getOutputStream() and response.getPrintWriter()

2)1)if i neeed binarydata can i use both response.getOutputStream() and response.getPrintWriter()
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anarkali perera wrote:1)if i neeed text data can i use both response.getOutputStream() and response.getPrintWriter()

2)1)if i neeed binarydata can i use both response.getOutputStream() and response.getPrintWriter()


No, you can't, you'll need a Reader or InputStream!
 
anarkali perera
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry.
response.getPrintWriter() should be change as response.getWriter()
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where would you need binary/text data and what would you use the streams/writers for..? You'd like to send it to the client, or what? Please clarify your question!
 
anarkali perera
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is
1)can i use both response.getWriter() and response.getOutputStream() for writing text data?

2)can i use both response.getWriter() and response.getOutputStream() for writing binary data?

 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should use getOutputStream() for binary and getWriter() for text data, because the latter will take care of the character encoding/MIME type of the response!
 
anarkali perera
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can't i use response.getOutputStream() for writing text data?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2)can i use both response.getWriter() and response.getOutputStream() for writing binary data?


NO - of course not. Writers attempt to put character data into a specific encoding. With binary input such as image data you get gibberish output.

Bill
 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use response.getOutput Writer() for writing text data.
 
anarkali perera
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can't i use response.get Writer (Writer.OUTPUT_BINARY) for writing text datda?
 
Praneeth Thiruveedhula
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)getOutPutStream(); is for both text and binary

2)getWriter(); is only for text data.

based on your requirement you can use it.
 
anarkali perera
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you give me a example for how to use getOutPutStream() for both text and binary ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic