Project

Profile

Help

Result file open after transform() in Saxon 9

Added by Anonymous over 15 years ago

Legacy ID: #7454002 Legacy Poster: Tomasz Wilku (wilczarz)

I believe the problem is well-known - result file can't be deleted until JVM is closed (on Windows, at least). Using StreamResult on both File and FileOutputStream has the same result. Closing the stream after transform call doesn't help. I see reports on this on very old releases.. wasn't it fixed? Am I doing soething wrong to still get this ? Any help apprieciated.


Replies (4)

Please register to reply

RE: Result file open after transform() in Saxon 9 - Added by Anonymous over 15 years ago

Legacy ID: #7454020 Legacy Poster: Michael Kay (mhkay)

You will have to explain in detail what you are doing. There are very many possible ways of invoking Saxon transformations, and I can only tackle the issue by reproducing what you are doing, seeing if I observe the same effects, and then analyzing their causes.

RE: Result file open after transform() in Saxon 9 - Added by Anonymous over 15 years ago

Legacy ID: #7454476 Legacy Poster: Tomasz Wilku (wilczarz)

Thanks for quick reply. This is a method of my java bean runned by JBoss AS: public void transform() throws Exception { System.setProperty( "javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl" ); TransformerFactory tfactory = TransformerFactory.newInstance(); Transformer transformer = tfactory.newTransformer( new StreamSource( new File( "D://foo.xsl" ) ) ); transformer.transform( new StreamSource( new File( "D://in.xml" ) ), new StreamResult( new File( "D://out.txt" ) ) ); } After invocation, file out.txt is created properly, but I have to stop Jboss to be able to delete it. I tried replacing the last line with: FileOutputStream os = new FileOutputStream( "out.txt" ); transformer.transform( new StreamSource( new File( "in.xml" ) ), new StreamResult( os ) ); os.flush(); os.close(); But the effect was the same.

RE: Result file open after transform() in Saxon 9 - Added by Anonymous over 15 years ago

Legacy ID: #7455530 Legacy Poster: Michael Kay (mhkay)

I ran the following program: public static void main(String[] args) throws Exception { System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl"); TransformerFactory tfactory = TransformerFactory.newInstance(); Transformer transformer = tfactory.newTransformer(new StreamSource(new File("c:/temp/books.xsl"))); transformer.transform(new StreamSource(new File("c:/temp/books.xml")), new StreamResult(new File("e:/temp/out.html"))); System.err.println("sleeping"); Thread.sleep(60000); System.err.println("waking"); System.err.println("Exists? " + new File("e:/temp/out.html").exists()); } and while the thread was sleeping, I deleted out.html from the command line. On waking, the message was "Exists? false". So in my environment, there is no problem deleting the file while the VM is still running. I'm therefore forced to conclude the problem is something particular to JBoss, which means I can't help you much. If you can find a way of reproducing the problem outside a JBoss environment, let me know.

RE: Result file open after transform() in Saxon 9 - Added by Anonymous over 15 years ago

Legacy ID: #7457311 Legacy Poster: Tomasz Wilku (wilczarz)

Michael, I've found the bug - I had unclosed FileReader on the output file hidden in the closet. I'm sorry to make you investigate this, it was too soon to blame Saxon. Which is great btw ;) Thanks for help!

    (1-4/4)

    Please register to reply