JDOM Document adapter to InputStream

Discussion in 'XML' started by Brian J. Sayatovic, Aug 20, 2004.

  1. 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.
    Brian J. Sayatovic, Aug 20, 2004
    #1
    1. Advertising

  2. /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
    Stanimir Stamenkov, Aug 20, 2004
    #2
    1. Advertising

  3. Brian J. Sayatovic

    GIMME Guest

    > 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.
    GIMME, Aug 24, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wendy S
    Replies:
    1
    Views:
    6,326
    Darren Davison
    Aug 5, 2003
  2. Bernd Oninger
    Replies:
    4
    Views:
    12,200
    GIMME
    Jun 21, 2004
  3. Brian J. Sayatovic

    JDOM Document adapter to InputStream

    Brian J. Sayatovic, Aug 20, 2004, in forum: Java
    Replies:
    2
    Views:
    415
    GIMME
    Aug 24, 2004
  4. R
    Replies:
    5
    Views:
    2,090
    Kevin McMurtrie
    Mar 13, 2005
  5. Tinker
    Replies:
    4
    Views:
    5,256
    Harry Bosch
    Oct 9, 2005
Loading...

Share This Page