Merge branch 'patch/JAL-3692enaEndpointFlatfile' into releases/Release_2_11_1_Branch
[jalview.git] / src / jalview / ws / ebi / EBIFetchClient.java
index 07a9df4..9a77087 100644 (file)
@@ -27,6 +27,7 @@ import java.io.BufferedInputStream;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
@@ -91,7 +92,7 @@ public class EBIFetchClient
    *          the query formatted as db:query1;query2;query3
    * @param format
    *          the format wanted
-   * @param extension
+   * @param ext
    *          for the temporary file to hold response (without separator)
    * @return the file holding the response
    * @throws OutOfMemoryError
@@ -201,7 +202,8 @@ public class EBIFetchClient
   {
     // long time = System.currentTimeMillis();
     String url = buildUrl(ids, database, format);
-
+    InputStream is = null;
+    BufferedReader br = null;
     try
     {
       URL rcall = new URL(url);
@@ -213,7 +215,7 @@ public class EBIFetchClient
         System.err.println("Warning: response code " + responseCode
                 + " for " + url);
       }
-      InputStream is = new BufferedInputStream(conn.getInputStream());
+      is = new BufferedInputStream(conn.getInputStream());
       if (outFile != null)
       {
         FileOutputStream fio = new FileOutputStream(outFile);
@@ -228,7 +230,7 @@ public class EBIFetchClient
       }
       else
       {
-        BufferedReader br = new BufferedReader(new InputStreamReader(is));
+        br = new BufferedReader(new InputStreamReader(is));
         String rtn;
         List<String> arl = new ArrayList<String>();
         while ((rtn = br.readLine()) != null)
@@ -257,6 +259,24 @@ public class EBIFetchClient
     {
       // System.err.println("EBIFetch took " + (System.currentTimeMillis() -
       // time) + " ms");
+      if (is != null)
+      {
+        try
+        {
+          is.close();
+        } catch (IOException e)
+        {
+        }
+      }
+      if (br != null)
+      {
+        try
+        {
+          br.close();
+        } catch (IOException e)
+        {
+        }
+      }
     }
     return null;
   }
@@ -275,8 +295,9 @@ public class EBIFetchClient
     if (database.equalsIgnoreCase(DBRefSource.EMBL)
             || database.equalsIgnoreCase(DBRefSource.EMBLCDS))
     {
-      url = "https://www.ebi.ac.uk/ena/data/view/" + ids.toLowerCase()
-              + (format != null ? "&" + format : "");
+//      url = "https://www.ebi.ac.uk/ena/data/view/" + ids.toLowerCase()
+//              + (format != null ? "&" + format : "");
+      url = "https://www.ebi.ac.uk/ena/browser/api/embl/" + ids.toLowerCase();
     }
     else
     {