aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/network/Network.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/network/Network.java')
-rw-r--r--main/src/cgeo/geocaching/network/Network.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/network/Network.java b/main/src/cgeo/geocaching/network/Network.java
index b737fd2..ffd58c3 100644
--- a/main/src/cgeo/geocaching/network/Network.java
+++ b/main/src/cgeo/geocaching/network/Network.java
@@ -47,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;
@@ -425,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 {