JDOM Document adapter to InputStream

B

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?

Regards,
Brian.
 
S

Stanimir Stamenkov

/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.
 
G

GIMME

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
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top