diff options
Diffstat (limited to 'main/src/cgeo/geocaching/network/Network.java')
| -rw-r--r-- | main/src/cgeo/geocaching/network/Network.java | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/main/src/cgeo/geocaching/network/Network.java b/main/src/cgeo/geocaching/network/Network.java index e891d3b..ffd58c3 100644 --- a/main/src/cgeo/geocaching/network/Network.java +++ b/main/src/cgeo/geocaching/network/Network.java @@ -34,7 +34,6 @@ import ch.boye.httpclientandroidlib.params.CoreProtocolPNames; import ch.boye.httpclientandroidlib.params.HttpParams; import ch.boye.httpclientandroidlib.protocol.HttpContext; import ch.boye.httpclientandroidlib.util.EntityUtils; - import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.Nullable; @@ -48,6 +47,7 @@ import android.net.Uri; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; @@ -426,6 +426,30 @@ public abstract class Network { return null; } + /** + * Get the input stream corresponding to a HTTP response if it exists. + * + * @param response a HTTP response, which can be null + * @return the input stream if the HTTP request is successful, <code>null</code> otherwise + */ + @Nullable + public static InputStream getResponseStream(@Nullable final HttpResponse response) { + if (!isSuccess(response)) { + return null; + } + assert(response != null); + final HttpEntity entity = response.getEntity(); + if (entity == null) { + return null; + } + try { + return entity.getContent(); + } catch (final IOException e) { + Log.e("Network.getResponseStream", e); + return null; + } + } + @Nullable private static String getResponseDataNoError(final HttpResponse response, boolean replaceWhitespace) { try { |
