Modified BioJsHTMLOutput.java to clean up and close used resources properly
authorCharles Ofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 7 Nov 2014 09:46:37 +0000 (09:46 +0000)
committerCharles Ofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 7 Nov 2014 09:46:37 +0000 (09:46 +0000)
src/jalview/io/BioJsHTMLOutput.java

index 7423e20..d4c9ba0 100644 (file)
@@ -104,24 +104,38 @@ public class BioJsHTMLOutput
   public static String getBioJsTemplateAsString(AlignmentI bio)
           throws IOException
   {
-     StringBuilder sb = new StringBuilder();
+    InputStreamReader isReader = null;
+    BufferedReader buffReader = null;
+    StringBuilder sb = new StringBuilder();
     URL url = bio.getClass().getResource(
             "/templates/BioJSTemplate.txt");
     if (url != null)
     {
       try
       {
-        BufferedReader reader = new BufferedReader(new InputStreamReader(
-                url.openStream()));
+        isReader = new InputStreamReader(url.openStream());
+        buffReader = new BufferedReader(isReader);
         String line;
         String lineSeparator = System.getProperty("line.separator");
-        while ((line = reader.readLine()) != null)
+        while ((line = buffReader.readLine()) != null)
         {
           sb.append(line).append(lineSeparator);
         }
+
       } catch (Exception ex)
       {
         ex.printStackTrace();
+      } finally
+      {
+        if (isReader != null)
+        {
+          isReader.close();
+        }
+
+        if (buffReader != null)
+        {
+          buffReader.close();
+        }
       }
     }