From 9c87de9029a55b2f0c584d6ce58668bd33e8ef63 Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Tue, 9 May 2017 17:15:08 +0100 Subject: [PATCH] JAL-2520 improvement to download and update structure files loaded via URL to a local file before parsing the file --- src/jalview/io/FileLoader.java | 13 +++++++++++++ src/jalview/ws/utils/UrlDownloadClient.java | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) 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; -- 1.7.10.2