You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Ziv Ben-Eliahu <zi...@wirexn.com> on 2006/12/04 13:45:37 UTC
Does javax.xml.transform.Transfomer close its streams?
I have the following code:
{
File outputFile = new File("out.xml");
Result outputResult = new StreamResult(outputFile);
File inputFile = new File("in.xml");
Result inputSource = new StreamSource(inputFile);
Transformer transformer = javax.xml.transform.TransformerFactory
.newInstance().newTransformer("stylesheet.xsl");
transformer.transform(inputSource, outputResult);
}
The default transformer instance is:
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl
After this code runs, I cannot delete the created "out.xml" file while
JVM is running. If I use FileOutputStream instead of File, and close the
stream myself, then I can delete the file.
It seems to me that the Java-1.5 default Transformer opens a stream and
does not close it.
Anyone knows if there is a different reason?
If no, do you know a non-default Transformer that closes the stream
(rather than creating a stream myself).
Thanks, Ziv.
Re: Does javax.xml.transform.Transfomer close its streams?
Posted by Santiago Pericas-Geertsen <Sa...@Sun.COM>.
Hi Ziv,
You're evaluation is correct. Fortunately, it appears that this has
been fixed in XSLTC at Apache (I haven't tried it myself, but can
tell by reading the source code). Please see [1] about downloading
and installing the Apache version.
Thanks.
-- Santiago
[1] http://xml.apache.org/xalan-j/downloads.html
On Dec 4, 2006, at 7:45 AM, Ziv Ben-Eliahu wrote:
> I have the following code:
>
> {
> File outputFile = new File("out.xml");
> Result outputResult = new StreamResult(outputFile);
>
>
> File inputFile = new File("in.xml");
> Result inputSource = new StreamSource(inputFile);
>
> Transformer transformer =
> javax.xml.transform.TransformerFactory
> .newInstance().newTransformer("stylesheet.xsl");
> transformer.transform(inputSource, outputResult);
> }
>
> The default transformer instance is:
> com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl
>
> After this code runs, I cannot delete the created "out.xml" file
> while JVM is running. If I use FileOutputStream instead of File,
> and close the stream myself, then I can delete the file.
> It seems to me that the Java-1.5 default Transformer opens a stream
> and does not close it.
> Anyone knows if there is a different reason?
> If no, do you know a non-default Transformer that closes the stream
> (rather than creating a stream myself).
>
> Thanks, Ziv.
>
>