Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > JDOM Document adapter to InputStream

Reply
Thread Tools

JDOM Document adapter to InputStream

 
 
Brian J. Sayatovic
Guest
Posts: n/a
 
      08-20-2004
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.
 
Reply With Quote
 
 
 
 
Stanimir Stamenkov
Guest
Posts: n/a
 
      08-20-2004
/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
 
Reply With Quote
 
 
 
 
GIMME
Guest
Posts: n/a
 
      08-24-2004
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
java.lang.NoSuchMethodError: org.jdom.Element: method getParent()Lorg/jdom/Element Tinker Java 4 10-09-2005 03:12 PM
confused: Socket InputStream != ServerSocker InputStream R Java 5 03-13-2005 07:26 AM
JDOM Document adapter to InputStream Brian J. Sayatovic Java 2 08-24-2004 09:05 PM
JDOM: java.lang.NoClassDefFoundError: org/jdom/Content Bernd Oninger Java 4 06-21-2004 09:08 PM
Help with JDOM, turn org.jdom.Document -> org.w3c.dom.Document? Wendy S Java 1 08-04-2003 11:48 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57