Skip to content

Commit

Permalink
TIKA-4236: use try-with-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
THausherr committed Apr 6, 2024
1 parent b86ebb4 commit 6d47c6c
Showing 1 changed file with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
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;
Expand Down Expand Up @@ -65,9 +65,7 @@ public GeoGazetteerClient(GeoParserConfig config) {
* @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);
Expand Down Expand Up @@ -96,9 +94,7 @@ public Map<String, List<Location>> getLocations(List<String> locations) {
* @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);
Expand Down

0 comments on commit 6d47c6c

Please sign in to comment.