+/* 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
\r
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
* @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
* @param result\r
* the AACon scores to output\r
*/\r
- static void writeOut(OutputStream outStream, ScoreManager results) {\r
+ static void writeOut(Writer writer, ScoreManager results) {\r
+ if (results == null) {\r
+ return;\r
+ }\r
try {\r
- results.writeOut(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