Updated Branches: refs/heads/master d0c3586e4 -> 8fa8aeac9
THRIFT-1641 Thrift 0.8 not compatible with Android HttpClient Patch: Darin Tay Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/8fa8aeac Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/8fa8aeac Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/8fa8aeac Branch: refs/heads/master Commit: 8fa8aeac9a0f2ff4f11ac0ef73fc677bebd7a75f Parents: d0c3586 Author: Roger Meier <[email protected]> Authored: Sat Dec 22 19:46:28 2012 +0100 Committer: Roger Meier <[email protected]> Committed: Sat Dec 22 19:46:28 2012 +0100 ---------------------------------------------------------------------- .../org/apache/thrift/transport/THttpClient.java | 20 +++++++++++++- 1 files changed, 18 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/8fa8aeac/lib/java/src/org/apache/thrift/transport/THttpClient.java ---------------------------------------------------------------------- diff --git a/lib/java/src/org/apache/thrift/transport/THttpClient.java b/lib/java/src/org/apache/thrift/transport/THttpClient.java index 30f59ee..5a5b37c 100644 --- a/lib/java/src/org/apache/thrift/transport/THttpClient.java +++ b/lib/java/src/org/apache/thrift/transport/THttpClient.java @@ -29,6 +29,7 @@ import java.net.HttpURLConnection; import java.util.HashMap; import java.util.Map; +import org.apache.http.HttpEntity; import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; @@ -36,7 +37,6 @@ import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.params.CoreConnectionPNames; -import org.apache.http.util.EntityUtils; /** * HTTP implementation of the TTransport interface. Used for working with a @@ -197,6 +197,22 @@ public class THttpClient extends TTransport { requestBuffer_.write(buf, off, len); } + /** + * copy from org.apache.http.util.EntityUtils#consume. Android has it's own httpcore + * that doesn't have a consume. + */ + private static void consume(final HttpEntity entity) throws IOException { + if (entity == null) { + return; + } + if (entity.isStreaming()) { + InputStream instream = entity.getContent(); + if (instream != null) { + instream.close(); + } + } + } + private void flushUsingHttpClient() throws TTransportException { if (null == this.client) { @@ -266,7 +282,7 @@ public class THttpClient extends TTransport { try { // Indicate we're done with the content. - EntityUtils.consume(response.getEntity()); + consume(response.getEntity()); } catch (IOException ioe) { // We ignore this exception, it might only mean the server has no // keep-alive capability.
