JAL-4090 JAL-1551 spotlessApply
[jalview.git] / src / jalview / ws / ebi / EBIFetchClient.java
index b5a7328..8aca9a2 100644 (file)
@@ -20,6 +20,8 @@
  */
 package jalview.ws.ebi;
 
+import java.util.Locale;
+
 import jalview.datamodel.DBRefSource;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
@@ -91,7 +93,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
@@ -134,8 +136,10 @@ public class EBIFetchClient
     String database = parseIds(ids, querystring);
     if (database == null)
     {
-      System.err.println("Invalid Query string : '" + ids + "'");
-      System.err.println("Should be of form 'dbname:q1;q2;q3;q4'");
+      jalview.bin.Console
+              .errPrintln("Invalid Query string : '" + ids + "'");
+      jalview.bin.Console
+              .errPrintln("Should be of form 'dbname:q1;q2;q3;q4'");
       return null;
     }
 
@@ -202,6 +206,7 @@ public class EBIFetchClient
   {
     String url = buildUrl(ids, database, format);
     InputStream is = null;
+    BufferedReader br = null;
     try
     {
       URL rcall = new URL(url);
@@ -215,7 +220,7 @@ public class EBIFetchClient
           Platform.streamToFile(is, outFile);
           return null;
         }
-        BufferedReader br = new BufferedReader(new InputStreamReader(is));
+        br = new BufferedReader(new InputStreamReader(is));
         String rtn;
         List<String> arl = new ArrayList<>();
         while ((rtn = br.readLine()) != null)
@@ -224,20 +229,21 @@ public class EBIFetchClient
         }
         return (String[]) arl.toArray();
       }
-      System.err.println(
+      jalview.bin.Console.errPrintln(
               "Warning: response code " + responseCode + " for " + url);
     } catch (OutOfMemoryError er)
     {
-      System.out.println("OUT OF MEMORY DOWNLOADING QUERY FROM " + database
-              + ":\n" + ids);
+      jalview.bin.Console.outPrintln("OUT OF MEMORY DOWNLOADING QUERY FROM "
+              + database + ":\n" + ids);
       throw er;
     } catch (Exception ex)
     {
       if (!ex.getMessage().startsWith(
               "uk.ac.ebi.jdbfetch.exceptions.DbfNoEntryFoundException"))
       {
-        System.err.println("Unexpected exception when retrieving from "
-                + database + "\nQuery was : '" + ids + "'");
+        jalview.bin.Console
+                .errPrintln("Unexpected exception when retrieving from "
+                        + database + "\nQuery was : '" + ids + "'");
         ex.printStackTrace(System.err);
       }
     } finally
@@ -251,10 +257,24 @@ public class EBIFetchClient
         {
         }
       }
+      if (br != null)
+      {
+        try
+        {
+          br.close();
+        } catch (IOException e)
+        {
+        }
+      }
     }
     return null;
   }
 
+  static
+  {
+    Platform.addJ2SDirectDatabaseCall("https://www.ebi.ac.uk/");
+  }
+
   /**
    * Constructs the URL to fetch from
    * 
@@ -269,13 +289,14 @@ 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/browser/api/embl/"
+              + ids.toLowerCase(Locale.ROOT) + "?download=true&gzip=true";
     }
     else
     {
       url = "https://www.ebi.ac.uk/Tools/dbfetch/dbfetch/"
-              + database.toLowerCase() + "/" + ids.toLowerCase()
+              + database.toLowerCase(Locale.ROOT) + "/"
+              + ids.toLowerCase(Locale.ROOT)
               + (format != null ? "/" + format : "");
     }
     return url;