From c958992ac5ee0846e647e74d1bc0599c039c00d4 Mon Sep 17 00:00:00 2001 From: Charles Ofoegbu Date: Fri, 7 Nov 2014 09:46:37 +0000 Subject: [PATCH] Modified BioJsHTMLOutput.java to clean up and close used resources properly --- src/jalview/io/BioJsHTMLOutput.java | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/jalview/io/BioJsHTMLOutput.java b/src/jalview/io/BioJsHTMLOutput.java index 7423e20..d4c9ba0 100644 --- a/src/jalview/io/BioJsHTMLOutput.java +++ b/src/jalview/io/BioJsHTMLOutput.java @@ -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(); + } } } -- 1.7.10.2