JDOM Document adapter to InputStream

  • Follow


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.
0
Reply trin (39) 8/20/2004 7:50:32 PM

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

-- 
Stanimir
0
Reply s7an10 (253) 8/20/2004 9:03:23 PM


> 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.
0
Reply gimme_this_gimme_that (274) 8/24/2004 9:05:42 PM

2 Replies
22 Views

(page loaded in 0.047 seconds)


Reply: