IntelliJ open source
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of JBoss AS 5 Development this week in the JBoss forum
or Spring Dynamic Modules in Action in the Spring forum!
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Java in General
 
RSS feed
 
New topic
Author

StreamResult to a String?

Scott Simpson
Greenhorn

Joined: Mar 03, 2005
Messages: 3

I need to figure out how to make something go from a StreamResult into a String in this:


the StreamResult param of that would usually take a FileStream or something, but i need it in a String or StringBuffer format. Can anyone help me? THanks in advance

-scott-<br />trying to like java
Horatio Westock
Ranch Hand

Joined: Feb 23, 2005
Messages: 221

Hi.

You could write a StringOutputStream that extends OutputStream, then pass that to the approriate constructor of StreamResult.

It should be fairly simple to implement with a StringBuffer at it's core.

In fact, a cursory glance at google came up with this implementation which you could draw inspiration from.

Hope this helps.

/edit

Ignore me, I'm being silly!

Just use StringWriter

e.g.


[ March 08, 2005: Message edited by: Horatio Westock ]
Scott Simpson
Greenhorn

Joined: Mar 03, 2005
Messages: 3

thanks a bunch! that last bit is exactly what i needed. wasn't too familiar with the StreamResult stuff.

-scott-<br />trying to like java
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Messages: 1641

Originally posted by Scott Simpson:
trying to like java
Do, or do not. There is no try.

Sorry, couldn't resist.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Messages: 14088

Originally posted by David Harkness:
Do, or do not. There is no try.

Sorry, couldn't resist.


"Do and Undo. There is always try." - Ronald E. Jeffries


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Java in General
 
RSS feed
 
New topic
MyEclipse Enterprise Workbench