This is an automated email from the ASF dual-hosted git repository.

tilman pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git


The following commit(s) were added to refs/heads/main by this push:
     new e559bc77b TIKA-4236: use try-with-resources
e559bc77b is described below

commit e559bc77b98512d215b4c476946779aa2d783a96
Author: Tilman Hausherr <[email protected]>
AuthorDate: Sat Apr 6 11:22:37 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 f4bee070d..12cc5fc16 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.reflect.TypeToken;
 import org.apache.commons.io.Charsets;
 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);

Reply via email to