From: Jim Procter Date: Wed, 17 Jun 2015 20:50:15 +0000 (+0100) Subject: JAL-1784 refactor parse method to directly parse FileParser input reader stream. X-Git-Tag: Release_2_10_0~296^2~137^2~17 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=93d63f3c608771bb48b5ac18f761194a1ea28554;p=jalview.git JAL-1784 refactor parse method to directly parse FileParser input reader stream. --- diff --git a/src/jalview/io/HtmlFile.java b/src/jalview/io/HtmlFile.java index 73aa5d2..e847c58 100644 --- a/src/jalview/io/HtmlFile.java +++ b/src/jalview/io/HtmlFile.java @@ -22,6 +22,7 @@ package jalview.io; import java.io.IOException; +import java.io.StringReader; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; @@ -75,9 +76,7 @@ public class HtmlFile extends AlignFile implements ComplexAlignFile Document doc = Jsoup.parse(htmlData.toString()); Element content = doc.getElementById("seqData"); - String alignmentJsonString = content.val(); - - JSONFile jsonFile = new JSONFile().parse(alignmentJsonString); + JSONFile jsonFile = new JSONFile().parse(new StringReader(content.val())); this.seqs = jsonFile.getSeqs(); this.seqGroups = jsonFile.getSeqGroups(); this.annotations = jsonFile.getAnnotations(); diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index f977b04..bbbc122 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -21,18 +21,6 @@ package jalview.io; -import java.awt.Color; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; - import jalview.api.AlignViewportI; import jalview.api.ComplexAlignFile; import jalview.api.FeatureRenderer; @@ -55,6 +43,19 @@ import jalview.json.binding.v1.SequencePojo; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; +import java.awt.Color; +import java.io.IOException; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Vector; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; + public class JSONFile extends AlignFile implements ComplexAlignFile { private ColourSchemeI colourScheme; @@ -105,13 +106,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile @Override public void parse() throws IOException { - StringBuilder jsonStringBuilder = new StringBuilder(); - String currentLine; - while ((currentLine = nextLine()) != null) - { - jsonStringBuilder.append(currentLine); - } - parse(jsonStringBuilder.toString()); + parse(getReader()); } @@ -354,7 +349,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile } @SuppressWarnings("unchecked") - public JSONFile parse(String jsonAlignmentString) + public JSONFile parse(Reader jsonAlignmentString) { try {