JDOM Document adapter to InputStream

Brian J. Sayatovic

Usenet Archive
Joined
Jun 9, 2000
Messages
52
Reaction score
0
I have a need to adapt a JDOM Document to an InputStream. I am building the Document in memory, but then need to serve it via a Java Activation Framework DataSource which deals in InputStreams. Normally, JDOM prefers to write to OutputStreams directly, but that will not fit this case.

Currently, I'm writing the whole Document to a ByteArrayOutputStream and then using the generated byte to back a ByteArrayInputStream. This is a lot of extra work that is consuming memory and wasting time.

I can vaguely conceive of how to write my own adapter, but I was hoping someone else has already tackled this.

Any ideas?

Regards,
Brian.
 

Stanimir Stamenkov

Usenet Archive
Joined
Dec 2, 2002
Messages
431
Reaction score
0
/Brian J. Sayatovic/:
I have a need to adapt a JDOM Document to an InputStream. I am building the Document in memory, but then need to serve it via a Java Activation Framework DataSource which deals in InputStreams. Normally, JDOM prefers to write to OutputStreams directly, but that will not fit this case.

Currently, I'm writing the whole Document to a ByteArrayOutputStream and then using the generated byte to back a ByteArrayInputStream. This is a lot of extra work that is consuming memory and wasting time.

I can vaguely conceive of how to write my own adapter, but I was hoping someone else has already tackled this.

Any ideas?

There are piped streams (java.io.PipedOutputStream /
java.io.PipedInputStream). Note you must use two threads - the one where you're feeding the data through the output and the other reading and processing it through the input.
 

GIMME

Usenet Archive
Joined
Jun 3, 2003
Messages
107
Reaction score
0
Any ideas?
Write your JDOM object to a String variable with XMLOutputter's outputString method. Then create an InputStream from something like String's NewStringReader.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top