From caae1fa9e2ea69a8e415602559d1ac56a879d15b Mon Sep 17 00:00:00 2001 From: Mark Anderson Date: Wed, 25 Mar 2015 22:22:51 +0000 Subject: [PATCH] NetworkUtils changes from removing redirect --- .../src/com/newsblur/util/NetworkUtils.java | 23 ++++--------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/clients/android/NewsBlur/src/com/newsblur/util/NetworkUtils.java b/clients/android/NewsBlur/src/com/newsblur/util/NetworkUtils.java index b93d81a84..fe6d98977 100644 --- a/clients/android/NewsBlur/src/com/newsblur/util/NetworkUtils.java +++ b/clients/android/NewsBlur/src/com/newsblur/util/NetworkUtils.java @@ -11,7 +11,6 @@ import com.squareup.okhttp.Response; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.net.HttpURLConnection; import java.net.URL; import java.util.concurrent.TimeUnit; @@ -31,38 +30,24 @@ public class NetworkUtils { return (netInfo != null && netInfo.isConnected()); } - public static UrlLoadResult loadURL(URL url, OutputStream outputStream) throws IOException { - UrlLoadResult result = new UrlLoadResult(); + public static int loadURL(URL url, OutputStream outputStream) throws IOException { + int bytesRead = 0; try { Request.Builder requestBuilder = new Request.Builder().url(url); Response response = httpClient.newCall(requestBuilder.build()).execute(); if (response.isSuccessful()) { - int code = response.code(); - // we explicitly requested redirects, so if we still get one, it is because of a protocol - // change. inform the caller by returning the new URL - if ((code == HttpURLConnection.HTTP_MOVED_TEMP) || (code == HttpURLConnection.HTTP_MOVED_PERM)) { - String loc = response.header("Location"); - result.redirUrl = loc; - return result; - } InputStream inputStream = response.body().byteStream(); byte[] b = new byte[1024]; int read; while ((read = inputStream.read(b)) != -1) { outputStream.write(b, 0, read); - result.bytesRead += read; + bytesRead += read; } } } catch (Throwable t) { // a huge number of things could go wrong fetching and storing an image. don't spam logs with them } - return result; + return bytesRead; } - - public static class UrlLoadResult extends Object { - public int bytesRead; - public String redirUrl; - } - }