[jdom-interest] JDOM -> Xalan using PipedStreams
newsham at hotu.com
newsham at hotu.com
Thu Aug 2 11:55:47 PDT 2001
"Karachiwala, Aslam" wrote:
> Hello.
>
> Re. the thread included below, Markus, I'd appreciate your updated sample.
>
> Here's what we're trying to do w/ JDOM & Xalan (rls jdom-b7)...
>
> - construct XML output from a JDBC resultset via JDOM & write it to a
> PipedOutputStream (pos)
>
> - connect pos to the PipedInputStream (pis) from which I create a
> StreamSource (srcxml)
>
> - create new Transformer instance (xformer) from TransformerFactory for the
> StreamSource created from the stylesheet file (srcxls)
>
> - call xformer.transform(srcxml, streamResult)
>
> We find that the above call to transform() simply "hangs." The only case in
> which it succeeds is when srcxls & srcxml are created from filepaths of
> actual files on disk (doing this with even File objects didn't work). We've
> verified that all's OK with the XML constructed and fed to the transformer.
> We've been able to successfully write to streamResult instances created from
> File as well as FileOutputStream objects.
>
> BTW, I also tried mimicking the example in Brett's tip --
> http://www-106.ibm.com/developerworks/java/library/x-tipjdom.html -- without
> luck.
>
> Any ideas, anyone?
>
> --aslam
Are you sure it is hanging on xformer.transform()? If you are using piped streams
in a single thread (as is done in Brett's tip), you may deadlock while writing to
the PipedOutputStream. According to the PipedOutputStream javadocs, "Attempting to
use both objects from a single thread is not recommended as it may deadlock the
thread." I have had code based on Brett's tip deadlock on some input, and succeed
on other input (probably based on file size). I fixed this by spawning a new thread
to write to the output stream and then quit.
Jim
More information about the jdom-interest
mailing list