http service: close response body
This commit is contained in:
@@ -32,6 +32,7 @@ import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import org.apache.commons.csv.CSVFormat;
|
||||
import org.apache.commons.csv.CSVParser;
|
||||
import org.apache.commons.csv.CSVRecord;
|
||||
@@ -53,8 +54,14 @@ public class HiscoreService
|
||||
.build();
|
||||
|
||||
Response response = client.newCall(request).execute();
|
||||
String responseStr;
|
||||
|
||||
try (ResponseBody body = response.body())
|
||||
{
|
||||
responseStr = body.string();
|
||||
}
|
||||
|
||||
CSVParser parser = CSVParser.parse(response.body().string(), CSVFormat.DEFAULT);
|
||||
CSVParser parser = CSVParser.parse(responseStr, CSVFormat.DEFAULT);
|
||||
|
||||
HiscoreResultBuilder hiscoreBuilder = new HiscoreResultBuilder();
|
||||
hiscoreBuilder.setPlayer(username);
|
||||
|
||||
@@ -35,6 +35,7 @@ import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
public class WorldsService
|
||||
{
|
||||
@@ -50,8 +51,12 @@ public class WorldsService
|
||||
.build();
|
||||
|
||||
Response response = client.newCall(request).execute();
|
||||
byte[] b;
|
||||
|
||||
byte[] b = response.body().bytes();
|
||||
try (ResponseBody body = response.body())
|
||||
{
|
||||
b = body.bytes();
|
||||
}
|
||||
|
||||
List<World> worlds = new ArrayList<>();
|
||||
ByteBuffer buf = ByteBuffer.wrap(b);
|
||||
|
||||
Reference in New Issue
Block a user