From 06f3ea9a79fc32e4c036f8e57b7245b4cf396b29 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 12 Feb 2016 10:32:26 +0100 Subject: [PATCH] Support other URL types --- .../java/eu/faircode/netguard/DownloadTask.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/netguard/DownloadTask.java b/app/src/main/java/eu/faircode/netguard/DownloadTask.java index 61ec0fbf..bbcf9f10 100644 --- a/app/src/main/java/eu/faircode/netguard/DownloadTask.java +++ b/app/src/main/java/eu/faircode/netguard/DownloadTask.java @@ -14,6 +14,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; +import java.net.URLConnection; public class DownloadTask extends AsyncTask { private static final String TAG = "NetGuard.Download"; @@ -68,13 +69,16 @@ public class DownloadTask extends AsyncTask { InputStream in = null; OutputStream out = null; - HttpURLConnection connection = null; + URLConnection connection = null; try { - connection = (HttpURLConnection) url.openConnection(); + connection = url.openConnection(); connection.connect(); - if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) - throw new IOException(connection.getResponseCode() + " " + connection.getResponseMessage()); + if (connection instanceof HttpURLConnection) { + HttpURLConnection httpConnection = (HttpURLConnection) connection; + if (httpConnection.getResponseCode() != HttpURLConnection.HTTP_OK) + throw new IOException(httpConnection.getResponseCode() + " " + httpConnection.getResponseMessage()); + } int contentLength = connection.getContentLength(); Log.i(TAG, "Content length=" + contentLength); @@ -110,8 +114,8 @@ public class DownloadTask extends AsyncTask { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } - if (connection != null) - connection.disconnect(); + if (connection instanceof HttpURLConnection) + ((HttpURLConnection) connection).disconnect(); } }