Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / src / jalview / ws / utils / UrlDownloadClient.java
index e2fb1b8..a00e8b3 100644 (file)
 
 package jalview.ws.utils;
 
-import jalview.util.Platform;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.net.URL;
-import java.nio.channels.Channels;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.StandardCopyOption;
+import jalview.util.Platform;
 
 public class UrlDownloadClient
 {
+  public UrlDownloadClient()
+  {
+
+  }
+
   /**
    * Download and save a file from a URL
    * 
@@ -49,67 +46,11 @@ public class UrlDownloadClient
           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
+  public static void download(String urlstring, File tempFile) throws IOException
   {
     if (!Platform.setFileBytes(tempFile, urlstring))
     {