in progress
[jalview.git] / forester / java / src / org / forester / io / writers / PhylogenyWriter.java
index 6aee097..911ebb5 100644 (file)
@@ -27,7 +27,6 @@ package org.forester.io.writers;
 
 import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
@@ -54,17 +53,17 @@ public final class PhylogenyWriter {
     public final static String          PHYLO_XML_INTENDATION_BASE      = "  ";
     public final static String          PHYLO_XML_VERSION_ENCODING_LINE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
     public final static String          PHYLO_XML_NAMESPACE_LINE        = "<phyloxml xmlns:xsi=\""
-                                                                                + ForesterConstants.XML_SCHEMA_INSTANCE
-                                                                                + "\" xsi:schemaLocation=\""
-                                                                                + ForesterConstants.PHYLO_XML_LOCATION
-                                                                                + " "
-                                                                                + ForesterConstants.PHYLO_XML_LOCATION
-                                                                                + "/"
-                                                                                + ForesterConstants.PHYLO_XML_VERSION
-                                                                                + "/" + ForesterConstants.PHYLO_XML_XSD
-                                                                                + "\" " + "xmlns=\""
-                                                                                + ForesterConstants.PHYLO_XML_LOCATION
-                                                                                + "\">";
+            + ForesterConstants.XML_SCHEMA_INSTANCE
+            + "\" xsi:schemaLocation=\""
+            + ForesterConstants.PHYLO_XML_LOCATION
+            + " "
+            + ForesterConstants.PHYLO_XML_LOCATION
+            + "/"
+            + ForesterConstants.PHYLO_XML_VERSION
+            + "/" + ForesterConstants.PHYLO_XML_XSD
+            + "\" " + "xmlns=\""
+            + ForesterConstants.PHYLO_XML_LOCATION
+            + "\">";
     public final static String          PHYLO_XML_END                   = "</phyloxml>";
     private boolean                     _saw_comma;
     private StringBuffer                _buffer;
@@ -112,7 +111,7 @@ public final class PhylogenyWriter {
         if ( tree.getConfidence() != null ) {
             if ( ForesterUtil.isEmpty( tree.getConfidence().getType() ) ) {
                 PhylogenyDataUtil.appendElement( writer, PhyloXmlMapping.CONFIDENCE, tree.getConfidence().getValue()
-                        + "", indentation );
+                                                 + "", indentation );
             }
             PhylogenyDataUtil.appendElement( writer,
                                              PhyloXmlMapping.CONFIDENCE,
@@ -399,7 +398,7 @@ public final class PhylogenyWriter {
 
     public void toNexus( final File out_file, final Phylogeny tree, final NH_CONVERSION_SUPPORT_VALUE_STYLE svs )
             throws IOException {
-        final Writer writer = new BufferedWriter( new PrintWriter( out_file ) );
+        final Writer writer = new BufferedWriter( new PrintWriter( out_file, ForesterConstants.UTF_8 ) );
         final List<Phylogeny> trees = new ArrayList<Phylogeny>( 1 );
         trees.add( tree );
         writeNexusStart( writer );
@@ -426,14 +425,14 @@ public final class PhylogenyWriter {
                             final List<Phylogeny> trees,
                             final int phyloxml_level,
                             final String separator ) throws IOException {
-        final Writer writer = new BufferedWriter( new PrintWriter( out_file ) );
+        final Writer writer = new BufferedWriter( new PrintWriter( out_file, ForesterConstants.UTF_8 ) );
         toPhyloXML( writer, trees, phyloxml_level, separator );
         writer.flush();
         writer.close();
     }
 
     public void toPhyloXML( final File out_file, final Phylogeny tree, final int phyloxml_level ) throws IOException {
-        final Writer writer = new BufferedWriter( new PrintWriter( out_file ) );
+        final Writer writer = new BufferedWriter( new PrintWriter( out_file, ForesterConstants.UTF_8 ) );
         writePhyloXmlStart( writer );
         toPhyloXMLNoPhyloXmlSource( writer, tree, phyloxml_level );
         writePhyloXmlEnd( writer );
@@ -583,7 +582,7 @@ public final class PhylogenyWriter {
                     PhylogenyDataUtil.appendOpen( getWriter(),
                                                   PhyloXmlMapping.CLADE,
                                                   PhyloXmlMapping.NODE_COLLAPSE,
-                                                  "true" );
+                            "true" );
                 }
                 else {
                     PhylogenyDataUtil.appendOpen( getWriter(), PhyloXmlMapping.CLADE );
@@ -633,18 +632,8 @@ public final class PhylogenyWriter {
         if ( out_file.exists() ) {
             throw new IOException( "attempt to overwrite existing file \"" + out_file.getAbsolutePath() + "\"" );
         }
-        final PrintWriter out = new PrintWriter( new FileWriter( out_file ), true );
-        if ( getOutputFormt() == FORMAT.PHYLO_XML ) {
-            out.print( PHYLO_XML_VERSION_ENCODING_LINE );
-            out.print( ForesterUtil.LINE_SEPARATOR );
-            out.print( PHYLO_XML_NAMESPACE_LINE );
-            out.print( ForesterUtil.LINE_SEPARATOR );
-        }
+        final PrintWriter out = new PrintWriter( out_file, ForesterConstants.UTF_8 );
         out.print( sb );
-        if ( getOutputFormt() == FORMAT.PHYLO_XML ) {
-            out.print( ForesterUtil.LINE_SEPARATOR );
-            out.print( PHYLO_XML_END );
-        }
         out.flush();
         out.close();
     }
@@ -758,3 +747,7 @@ public final class PhylogenyWriter {
         NH, NHX, PHYLO_XML, NEXUS;
     }
 }
+
+
+
+