X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Futils%2FUrlDownloadClient.java;h=227fe2335a98804aec5158c472861af5ae627d09;hb=401715f8745eeee967df8d60549b4c5d7f64530f;hp=055df157196ed1205c8fcf778e6ec405552c656e;hpb=26b115b0a77d521da92a06572d9b7819c2d0d49a;p=jalview.git diff --git a/src/jalview/ws/utils/UrlDownloadClient.java b/src/jalview/ws/utils/UrlDownloadClient.java index 055df15..227fe23 100644 --- a/src/jalview/ws/utils/UrlDownloadClient.java +++ b/src/jalview/ws/utils/UrlDownloadClient.java @@ -23,7 +23,6 @@ package jalview.ws.utils; import jalview.util.Platform; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -54,75 +53,13 @@ public class UrlDownloadClient public static void download(String urlstring, String outfile) throws IOException { - - FileOutputStream fos = null; - ReadableByteChannel rbc = null; - Path temp = null; - try - { - temp = Files.createTempFile(".jalview_", ".tmp"); - - URL url = new URL(urlstring); - rbc = Channels.newChannel(url.openStream()); - fos = new FileOutputStream(temp.toString()); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - - // copy tempfile to outfile once our download completes - // incase something goes wrong - Files.copy(temp, Paths.get(outfile), - StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) - { - throw e; - } finally - { - try - { - if (fos != null) - { - fos.close(); - } - } catch (IOException e) - { - System.out.println( - "Exception while closing download file output stream: " - + e.getMessage()); - } - try - { - if (rbc != null) - { - rbc.close(); - } - } catch (IOException e) - { - System.out.println("Exception while closing download channel: " - + e.getMessage()); - } - try - { - if (temp != null) - { - Files.deleteIfExists(temp); - } - } catch (IOException e) - { - System.out.println("Exception while deleting download temp file: " - + e.getMessage()); - } - } - + Platform.download(urlstring, outfile); } public static void download(String urlstring, File tempFile) throws IOException { - // BH 2019.01.25 this said "...getFileAsBytes(..." which cannot work. - // maybe we cannot get here? - if (Platform.isJS()) { - /** @j2sNative - * tempFile._bytes = swingjs.JSUtil.getFileAsBytes$O(urlstring); - */ - } else { + if (!Platform.setFileBytes(tempFile, urlstring)) + { download(urlstring, tempFile.toString()); } }