From 263ae64817c7604150961e1c9c76554936ab994b Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 17 Jun 2015 21:54:39 +0100 Subject: [PATCH] JAL-1784 minimise data duplication, and report out of memory errors and other kinds of parsing problems to the user --- src/jalview/io/HtmlFile.java | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) 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); } } -- 1.7.10.2