My general policy on this (it may not always be correctly implemented) is: he who creates the inputStream is responsible for closing it. So if you create an InputStream and pass it as a Source to Saxon, you should close it on completion. But if you provide a file and Saxon opens the InputStream, Saxon should close it. (I've just checked with Norm Walsh, the spec lead on JAXP 1.3, who happens to be sitting opposite me this morning, and he agrees).
 
Michael Kay


From: saxon-help-admin@lists.sourceforge.net [mailto:saxon-help-admin@lists.sourceforge.net] On Behalf Of Nestel, Frank IZ/HZA-IOL
Sent: 22 June 2004 09:07
To: 'saxon-help@lists.sourceforge.net'
Cc: Gast, Thorsten IZ/HZA-IOL
Subject: [saxon] Who is closing the InputStream

Hello,
 
we've run in another problem with long running processes here. We feed XML via
new StreamSource(InputStream) sources into Saxon. When stylesheets change,
Saxon picks them up without stopping the Server process. On the long run we end
up with many open *.xsl Files stopping our server from working. It seems like
Saxons TransformerFactory.newTemplates() method does not close it's InputStreams.
 
A quick hack workarround, returning these below class from our
handcrafted resolve()
 
public class SafeStreamSource
        extends StreamSource
{
    public SafeStreamSource(InputStream is)
    {
        super(is);
    }
 
    protected void finalize()
        throws Throwable
    {
        super.finalize();
        getInputStream().close();
    }
}
 
does not help, since the call of the InputStream's close now depends on the
behaviour of garbage collection: Sometimes the SafeStreamSource is cleared
early and than the Stylesheetprocessor fails to read from the now closed
InputStream.
 
This Problem is with Saxon 6.5.3. Anything to recommend about this?
 
Thank you,
Frank Nestel