From: tcofoegbu Date: Tue, 9 May 2017 16:15:08 +0000 (+0100) Subject: JAL-2520 improvement to download and update structure files loaded via URL to a local... X-Git-Tag: Release_2_10_2~3^2~57^2~6 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=9c87de9029a55b2f0c584d6ce58668bd33e8ef63;p=jalview.git JAL-2520 improvement to download and update structure files loaded via URL to a local file before parsing the file --- diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 4f83ab1..0152cc4 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -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. diff --git a/src/jalview/ws/utils/UrlDownloadClient.java b/src/jalview/ws/utils/UrlDownloadClient.java index 86e3f76..dcd861a 100644 --- a/src/jalview/ws/utils/UrlDownloadClient.java +++ b/src/jalview/ws/utils/UrlDownloadClient.java @@ -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;