package jalview.ws.utils;
+import jalview.util.Platform;
+
+import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
public class UrlDownloadClient
{
- public UrlDownloadClient()
- {
-
- }
-
/**
* Download and save a file from a URL
*
* 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;
Path temp = null;
}
} catch (IOException e)
{
- System.out
- .println("Exception while closing download file output stream: "
+ jalview.bin.Console.outPrintln(
+ "Exception while closing download file output stream: "
+ e.getMessage());
}
try
}
} catch (IOException e)
{
- System.out.println("Exception while closing download channel: "
+ jalview.bin.Console
+ .outPrintln("Exception while closing download channel: "
+ e.getMessage());
}
try
}
} catch (IOException e)
{
- System.out.println("Exception while deleting download temp file: "
+ jalview.bin.Console
+ .outPrintln("Exception while deleting download temp file: "
+ e.getMessage());
}
}
+
+ }
+
+ public static void download(String urlstring, File tempFile)
+ throws IOException
+ {
+ if (!Platform.setFileBytes(tempFile, urlstring))
+ {
+ download(urlstring, tempFile.toString());
+ }
}
}