Skip to content

Commit d4ea74c

Browse files
author
Jose M. Palomar
committed
Change to close Response instances
1 parent d82a351 commit d4ea74c

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/main/java/com/convertapi/client/ConvertApi.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static CompletableFuture<ConversionResult> convert(String fromFormat, Str
4040
.addPathSegment(toFormat);
4141

4242
for (Param param : params) {
43-
if (param.getName().toLowerCase().equals("converter")) {
43+
if (param.getName().equalsIgnoreCase("converter")) {
4444
try {
4545
urlBuilder = urlBuilder
4646
.addPathSegment("converter")
@@ -77,8 +77,7 @@ public static CompletableFuture<ConversionResult> convert(String fromFormat, Str
7777
.build();
7878

7979
String bodyString;
80-
try {
81-
Response response = Http.getClient(config).newCall(request).execute();
80+
try (Response response = Http.getClient(config).newCall(request).execute()) {
8281
//noinspection ConstantConditions
8382
bodyString = response.body().string();
8483
if (response.code() != 200) {
@@ -107,8 +106,7 @@ public static User getUser(Config config) {
107106
.build();
108107

109108
String bodyString;
110-
try {
111-
Response response = Http.getClient().newCall(request).execute();
109+
try (Response response = Http.getClient().newCall(request).execute()) {
112110
//noinspection ConstantConditions
113111
bodyString = response.body().string();
114112
if (response.code() != 200) {

src/main/java/com/convertapi/client/Http.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ static CompletableFuture<InputStream> requestGet(String url) {
4949
static CompletableFuture<Void> requestDelete(String url) {
5050
return CompletableFuture.supplyAsync(() -> {
5151
Request request = getRequestBuilder().delete().url(url).build();
52-
try {
53-
getClient().newCall(request).execute();
52+
try (Response response = getClient().newCall(request).execute()) {
5453
} catch (IOException e) {
5554
throw new RuntimeException(e);
5655
}
@@ -76,8 +75,7 @@ static RemoteUploadResponse remoteUpload(String urlToFile, Config config) {
7675
.build();
7776

7877
String bodyString;
79-
try {
80-
Response response = Http.getClient().newCall(request).execute();
78+
try (Response response = Http.getClient().newCall(request).execute()) {
8179
//noinspection ConstantConditions
8280
bodyString = response.body().string();
8381
if (response.code() != 200) {

0 commit comments

Comments
 (0)