Change header template for a new version
[jabaws.git] / webservices / compbio / ws / client / IOHelper.java
index 79357e5..290e0e1 100644 (file)
@@ -1,21 +1,36 @@
+/* Copyright (c) 2011 Peter Troshin\r
+ *  \r
+ *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     \r
+ * \r
+ *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
+ *  Apache License version 2 as published by the Apache Software Foundation\r
+ * \r
+ *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
+ *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
+ *  License for more details.\r
+ * \r
+ *  A copy of the license is in apache_license.txt. It is also available here:\r
+ * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
+ * \r
+ * Any republication or derived work distributed in source code form\r
+ * must include this copyright and license notice.\r
+ */\r
 package compbio.ws.client;\r
 \r
 import static compbio.ws.client.Constraints.pseparator;\r
 \r
 import java.io.BufferedReader;\r
 import java.io.File;\r
-import java.io.FileNotFoundException;\r
-import java.io.FileOutputStream;\r
 import java.io.FileReader;\r
+import java.io.FileWriter;\r
 import java.io.IOException;\r
-import java.io.OutputStream;\r
+import java.io.Writer;\r
 import java.util.ArrayList;\r
 import java.util.List;\r
-import java.util.Set;\r
 \r
 import compbio.data.sequence.Alignment;\r
 import compbio.data.sequence.ClustalAlignmentUtil;\r
-import compbio.data.sequence.Score;\r
+import compbio.data.sequence.ScoreManager;\r
 \r
 public class IOHelper {\r
 \r
@@ -75,14 +90,9 @@ public class IOHelper {
                return params;\r
        }\r
 \r
-       static OutputStream getOutStream(File file) {\r
+       static Writer getWriter(File file) throws IOException {\r
                assert file != null && file.exists();\r
-               try {\r
-                       return new FileOutputStream(file);\r
-               } catch (FileNotFoundException e) {\r
-                       e.printStackTrace();\r
-               }\r
-               return null;\r
+               return new FileWriter(file);\r
        }\r
 \r
        /**\r
@@ -93,17 +103,17 @@ public class IOHelper {
         * @param align\r
         *            the alignment to output\r
         */\r
-       static void writeOut(OutputStream outStream, Alignment align) {\r
+       static void writeOut(Writer writer, Alignment align) {\r
                try {\r
-                       ClustalAlignmentUtil.writeClustalAlignment(outStream, align);\r
+                       ClustalAlignmentUtil.writeClustalAlignment(writer, align);\r
                } catch (IOException e) {\r
                        System.err\r
                                        .println("Problems writing output file! Stack trace is below: ");\r
                        e.printStackTrace();\r
                } finally {\r
-                       if (outStream != null) {\r
+                       if (writer != null) {\r
                                try {\r
-                                       outStream.close();\r
+                                       writer.close();\r
                                } catch (IOException ignored) {\r
                                        // e.printStackTrace();\r
                                }\r
@@ -118,17 +128,20 @@ public class IOHelper {
         * @param result\r
         *            the AACon scores to output\r
         */\r
-       static void writeOut(OutputStream outStream, Set<Score> result) {\r
+       static void writeOut(Writer writer, ScoreManager results) {\r
+               if (results == null) {\r
+                       return;\r
+               }\r
                try {\r
-                       Score.write(result, outStream);\r
+                       results.writeOut(writer);\r
                } catch (IOException e) {\r
                        System.err\r
                                        .println("Problems writing output file! Stack trace is below: ");\r
                        e.printStackTrace();\r
                } finally {\r
-                       if (outStream != null) {\r
+                       if (writer != null) {\r
                                try {\r
-                                       outStream.close();\r
+                                       writer.close();\r
                                } catch (IOException ignored) {\r
                                        // e.printStackTrace();\r
                                }\r