Should I use JavaNIO to pass file references to Saxon s9api?

55 Views Asked by At

I downloaded the Saxon 10 samples from the Saxonica website to get some examples on how to use the s9api.

I found all samples using the classic java.io.* classes to read and write files for the XSL transformation. I then tried to find any Saxon examples using the newer Java NIO and NIO.2 packages for I/O**.

But I had surprisingly no luck at all. And I wonder why.

To be more concrete, let's focus on two examples:

Does it make a real difference if I use the java.nio.file.Files class instead of classic java.io.File to tell the Serializer in what file to save the transformation results?

Path targetFile ...
transformer.newSerializer(Files.newOutputStream(targetFile));
transformer.newSerializer(Files.newBufferedWriter(targetFile));
transformer.newSerializer(targetFile.toFile()); // java.io.File

Or, on the input side, is one of the following better than the others?

Path targetFile ...    
transformer.transform(new StreamSource(Files.newInputStream(xml)), out);
transformer.transform(new StreamSource(Files.newBufferedReader(xml)), out);
transformer.transform(new StreamSource(xml.toFile()), out); // java.io.File

Or is the parameter type just a "file reference" and the Serializer and the StreamSource do their best no matter how I tell them what file to use.

0

There are 0 best solutions below