Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Putting a string object to an output stream

 
le taylom
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
My problem is this: I am using log4j as my logging mechansim. But I want to log my message (a string) to an output stream, read it off the output stream (with an input stream) and then put it onto a JMS Q.
Because a ByteArrayOutputStream is buffered this is the best choice for what I need to do. Now, I can easily place an int onto the output stream and read it off. But how do I do this with a String object?
Any help is greatly appreciated.
Regards
T
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should wrap your ByteArrayOutputStream with a DataOutputStream with which you can write any primitive type and String objects.
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!