Show
Ignore:
Timestamp:
05/26/10 18:16:57 (21 months ago)
Author:
amandel
Message:

#81 open the stream directly in StreamSource? to avoid whitespace in path issue.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/java/org/jcoderz/commons/util/XmlUtil.java

    r1523 r1633  
    3333package org.jcoderz.commons.util; 
    3434 
     35import java.io.File; 
     36import java.io.FileOutputStream; 
     37import java.io.IOException; 
     38import javax.xml.transform.stream.StreamResult; 
    3539import org.xml.sax.Attributes; 
    3640 
     
    329333   } 
    330334 
     335    /** 
     336     * Creae a stream result based on a File. 
     337     * Other than the default implementation not only the File is used to 
     338     * initialize the result, but also a Stream is opened and initialized. 
     339     * This works around an issue with whitespaces in the pathname which 
     340     * otherwise would lead to a file not found exception 
     341     * <pre> 
     342     * Error during transformation: javax.xml.transform.TransformerException: java.io.FileNotFoundException: ...%20... 
     343     *   at org.apache.xalan.transformer.TransformerImpl.createSerializationHandler(TransformerImpl.java:1218) 
     344     *   at org.apache.xalan.transformer.TransformerImpl.createSerializationHandler(TransformerImpl.java:1060) 
     345     *   at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1268) 
     346     *   at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1251) 
     347     *   .... 
     348     * </pre>. 
     349     * The caller must ensure that the created outputstream is closed. 
     350     * @param outFile the file to be used in the stream result. 
     351     * @return a new StreamResult piontint to the given File. 
     352     * @throws IOException in case of an issue while creating the stream. 
     353     */ 
     354    public static StreamResult createStreamResult(File outFile) 
     355        throws IOException 
     356    { 
     357        final StreamResult result = new StreamResult(outFile); 
     358        // set the stream directly to avoid issues with blanks in the 
     359        // filename. 
     360        result.setOutputStream(new FileOutputStream(outFile)); 
     361        return result; 
     362    } 
     363 
    331364   private static void indent (final int i, StringBuffer b) 
    332365   {