From: Jim Procter Date: Wed, 17 Jun 2015 20:54:39 +0000 (+0100) Subject: JAL-1784 minimise data duplication, and report out of memory errors and other kinds... X-Git-Tag: Release_2_10_0~296^2~137^2~16 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=263ae64817c7604150961e1c9c76554936ab994b;p=jalview.git JAL-1784 minimise data duplication, and report out of memory errors and other kinds of parsing problems to the user --- diff --git a/src/jalview/io/HtmlFile.java b/src/jalview/io/HtmlFile.java index e847c58..a4e9bf4 100644 --- a/src/jalview/io/HtmlFile.java +++ b/src/jalview/io/HtmlFile.java @@ -67,15 +67,23 @@ public class HtmlFile extends AlignFile implements ComplexAlignFile { try { - StringBuilder htmlData = new StringBuilder(); - String currentLine; - while ((currentLine = nextLine()) != null) - { - htmlData.append(currentLine); + Element content = null; + Document doc = null; + try { + StringBuilder htmlData = new StringBuilder(); + String currentLine; + while ((currentLine = nextLine()) != null) + { + htmlData.append(currentLine); + } + + doc = Jsoup.parse(htmlData.toString()); + } catch (OutOfMemoryError oom) { + errormessage = "Not enough memory to process HTML document"; + throw new IOException(errormessage); } - - Document doc = Jsoup.parse(htmlData.toString()); - Element content = doc.getElementById("seqData"); + content = doc.getElementById("seqData"); + JSONFile jsonFile = new JSONFile().parse(new StringReader(content.val())); this.seqs = jsonFile.getSeqs(); this.seqGroups = jsonFile.getSeqGroups(); @@ -86,7 +94,8 @@ public class HtmlFile extends AlignFile implements ComplexAlignFile this.columnSelection = jsonFile.getColumnSelection(); } catch (Exception e) { - e.printStackTrace(); + errormessage = "Failed to extract data from HTML document."; + throw new IOException("Unexpected exception whilst extracting JSon from HTML.",e); } }