You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by shreck <cm...@gmail.com> on 2018/06/06 12:53:54 UTC

Connection can't be release rightly when Content-Encoding=gzip by the code

 HttpResponse response = httpClient.execute(httpget);
        validateResponse(response, httpget);
        HttpEntity entity = response.getEntity();
        InputStream is;
        if (null != entity) {

            Header header = entity.getContentEncoding();

            if (header != null &&
header.getValue().equalsIgnoreCase("gzip")) {
                GzipDecompressingEntity gzipEntity = new
GzipDecompressingEntity(
                        entity);
                is = gzipEntity.getContent();
            } else {
                is = entity.getContent();
            }

            if(isPB){
                ByteArrayOutputStream byteArrayOutputStream = new
ByteArrayOutputStream();
                byte[] bytes = new byte[1024];
                int len = 0;
                while(( len= is.read(bytes)) != -1){
                    byteArrayOutputStream.write(bytes, 0, len);
                }
                byte[] temp = byteArrayOutputStream.toByteArray();
                result = new String(temp,"ISO8859-1");
            }else{
                ByteArrayOutputStream outStream = new
ByteArrayOutputStream();
                byte[] data = new byte[4096];
                int count = -1;
                while ((count = is.read(data, 0, 4096)) != -1)
                    outStream.write(data, 0, count);
                data = null;
                return new String(outStream.toByteArray(), encoding);
            }

        }



--
Sent from: http://httpcomponents.10934.n7.nabble.com/HttpClient-User-f11330.html

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org