needs to close GZIPInputStream manually
This commit is contained in:
fenghua.yu 2020-05-25 15:42:19 +08:00
parent fc5089602f
commit 34e50e73fd

View File

@ -129,8 +129,13 @@ public class HttpClient {
if (encodingGzip.equals(respHeaders.get(HttpHeaders.CONTENT_ENCODING))) {
inputStream = new GZIPInputStream(inputStream);
}
return new HttpResult(respCode, IoUtils.toString(inputStream, getCharset(conn)), respHeaders);
HttpResult httpResult = new HttpResult(respCode, IoUtils.toString(inputStream, getCharset(conn)), respHeaders);
//inputStream from HttpURLConnection can be closed automatically,but new GZIPInputStream can't be closed automatically
//so needs to close it manually
if (inputStream instanceof GZIPInputStream) {
inputStream.close();
}
return httpResult;
}
private static String getCharset(HttpURLConnection conn) {