Result file open after transform() in Saxon 9

2009-06-19
2012-10-08
  • Tomasz Wilku
    Tomasz Wilku
    2009-06-19

    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.

     
    • Tomasz Wilku
      Tomasz Wilku
      2009-06-22

      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!

       
    • Michael Kay
      Michael Kay
      2009-06-19

      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.

       
    • Tomasz Wilku
      Tomasz Wilku
      2009-06-19

      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.

       
      • Michael Kay
        Michael Kay
        2009-06-20

        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.