Merge branch 'alpha/JAL-3362_Jalview_212_alpha' into alpha/merge_212_JalviewJS_2112
[jalview.git] / src / jalview / ext / ensembl / EnsemblInfo.java
index 6920549..895598f 100644 (file)
@@ -23,7 +23,6 @@ package jalview.ext.ensembl;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefSource;
 
-import java.io.BufferedReader;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -33,8 +32,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.json.simple.JSONArray;
-import org.json.simple.parser.JSONParser;
 import org.json.simple.parser.ParseException;
 
 public class EnsemblInfo extends EnsemblRestClient
@@ -110,53 +107,16 @@ public class EnsemblInfo extends EnsemblRestClient
      * for convenience, pre-fill ensembl.org as the domain for "ENSEMBL"
      */
     divisions.put(DBRefSource.ENSEMBL.toUpperCase(), ensemblDomain);
-
-    BufferedReader br = null;
     try
     {
-      URL url = getDivisionsUrl(ensemblGenomesDomain);
-      if (url != null)
-      {
-        br = getHttpResponse(url, null);
-      }
-      parseResponse(br, ensemblGenomesDomain);
-    } catch (IOException e)
-    {
-      // ignore
-    } finally
-    {
-      if (br != null)
-      {
-        try
-        {
-          br.close();
-        } catch (IOException e)
-        {
-          // ignore
-        }
-      }
-    }
-  }
-
-  /**
-   * Parses the JSON response to /info/divisions, and add each to the lookup map
-   * 
-   * @param br
-   * @param domain
-   */
-  void parseResponse(BufferedReader br, String domain)
-  {
-    JSONParser jp = new JSONParser();
-
-    try
-    {
-      JSONArray parsed = (JSONArray) jp.parse(br);
-
-      Iterator rvals = parsed.iterator();
+      @SuppressWarnings("unchecked")
+         Iterator<Object> rvals = (Iterator<Object>) getJSON(getDivisionsUrl(ensemblGenomesDomain), null, -1, MODE_ITERATOR, null);
+      if (rvals == null)
+         return;
       while (rvals.hasNext())
       {
         String division = rvals.next().toString();
-        divisions.put(division.toUpperCase(), domain);
+        divisions.put(division.toUpperCase(), ensemblGenomesDomain);
       }
     } catch (IOException | ParseException | NumberFormatException e)
     {