2019-12-15 21:04:27 +01:00
|
|
|
package com.baeldung.httpclient;
|
2019-10-31 20:43:47 -05:00
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
2023-11-20 11:44:00 +02:00
|
|
|
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
|
|
|
|
|
import org.apache.hc.core5.http.HttpEntity;
|
|
|
|
|
|
2019-10-31 20:43:47 -05:00
|
|
|
public final class ResponseUtil {
|
|
|
|
|
private ResponseUtil() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void closeResponse(CloseableHttpResponse response) throws IOException {
|
|
|
|
|
if (response == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
final HttpEntity entity = response.getEntity();
|
|
|
|
|
if (entity != null) {
|
|
|
|
|
entity.getContent().close();
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
response.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|