JAL-2520 improvement to download and update structure files loaded via URL to a local...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Tue, 9 May 2017 16:15:08 +0000 (17:15 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Tue, 9 May 2017 16:15:08 +0000 (17:15 +0100)
src/jalview/io/FileLoader.java
src/jalview/ws/utils/UrlDownloadClient.java

index 4f83ab1..0152cc4 100755 (executable)
@@ -39,7 +39,9 @@ import jalview.json.binding.biojson.v1.ColourSchemeMapper;
 import jalview.schemes.ColourSchemeI;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.MessageManager;
+import jalview.ws.utils.UrlDownloadClient;
 
+import java.nio.file.Files;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
@@ -325,6 +327,17 @@ public class FileLoader implements Runnable
 
             // open a new source and read from it
             FormatAdapter fa = new FormatAdapter();
+            boolean downloadStructureFile = format.isStructureFile()
+                    && protocol.equals(DataSourceType.URL);
+            if (downloadStructureFile)
+            {
+              String structExt = format.getExtensions().split(",")[0];
+              String tempStructurefile = Files.createTempFile(".jalview_",
+                      "." + structExt).toString();
+              UrlDownloadClient.download(file, tempStructurefile);
+              file = tempStructurefile;
+              protocol = DataSourceType.FILE;
+            }
             al = fa.readFile(file, protocol, format);
             source = fa.getAlignFile(); // keep reference for later if
                                         // necessary.
index 86e3f76..dcd861a 100644 (file)
@@ -47,7 +47,8 @@ public class UrlDownloadClient
    *          the name of file to save the URLs to
    * @throws IOException
    */
-  public void download(String urlstring, String outfile) throws IOException
+  public static void download(String urlstring, String outfile)
+          throws IOException
   {
     FileOutputStream fos = null;
     ReadableByteChannel rbc = null;