This is an automated email from the ASF dual-hosted git repository.
tilman pushed a commit to branch branch_2x
in repository https://gitbox.apache.org/repos/asf/tika.git
The following commit(s) were added to refs/heads/branch_2x by this push:
new 6d47c6cfd TIKA-4236: use try-with-resources
6d47c6cfd is described below
commit 6d47c6cfda28ad36644c84939a0da45440b8ca10
Author: Tilman Hausherr <[email protected]>
AuthorDate: Sat Apr 6 11:22:21 2024 +0200
TIKA-4236: use try-with-resources
---
.../tika/parser/geo/topic/gazetteer/GeoGazetteerClient.java | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git
a/tika-parsers/tika-parsers-ml/tika-parser-nlp-module/src/main/java/org/apache/tika/parser/geo/topic/gazetteer/GeoGazetteerClient.java
b/tika-parsers/tika-parsers-ml/tika-parser-nlp-module/src/main/java/org/apache/tika/parser/geo/topic/gazetteer/GeoGazetteerClient.java
index 9017fcad1..a09af950f 100644
---
a/tika-parsers/tika-parsers-ml/tika-parser-nlp-module/src/main/java/org/apache/tika/parser/geo/topic/gazetteer/GeoGazetteerClient.java
+++
b/tika-parsers/tika-parsers-ml/tika-parser-nlp-module/src/main/java/org/apache/tika/parser/geo/topic/gazetteer/GeoGazetteerClient.java
@@ -26,9 +26,9 @@ import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -65,9 +65,7 @@ public class GeoGazetteerClient {
* @return Map of input location strings to gazetteer locations
*/
public Map<String, List<Location>> getLocations(List<String> locations) {
- HttpClient httpClient = HttpClientBuilder.create().build();
-
- try {
+ try (CloseableHttpClient httpClient =
HttpClientBuilder.create().build()) {
URIBuilder uri = new URIBuilder(url + SEARCH_API);
for (String loc : locations) {
uri.addParameter(SEARCH_PARAM, loc);
@@ -96,9 +94,7 @@ public class GeoGazetteerClient {
* @return true if API is available else returns false
*/
public boolean checkAvail() {
- HttpClient httpClient = HttpClientBuilder.create().build();
-
- try {
+ try (CloseableHttpClient httpClient =
HttpClientBuilder.create().build()) {
HttpGet httpGet = new HttpGet(url + PING);
HttpResponse resp = httpClient.execute(httpGet);