Usage of consumeContent() of HttpEntity

后端 未结 2 1147
你的背包
你的背包 2021-01-21 11:12

What is the purpose of consumeContent() of class or org.apache.http.HttpEntity in Android?

When should one use it ane can it have side effects?

I\'m

2条回答
  •  佛祖请我去吃肉
    2021-01-21 11:47

    As you can see in the javadoc, that method is deprecated. Don't use it. It's implementation-dependent. But it should be implemented as described:

    This method is called to indicate that the content of this entity is no longer required. All entity implementations are expected to release all allocated resources as a result of this method invocation

    Instead, you should be using EntityUtils.consume(HttpEntity) which is implemented as such

    public static void consume(final HttpEntity entity) throws IOException {
        if (entity == null) {
            return;
        }
        if (entity.isStreaming()) {
            final InputStream instream = entity.getContent();
            if (instream != null) {
                instream.close();
            }
        }
    } 
    

    It's simply closing the underlying InputStream if necessary.

提交回复
热议问题