http service: close response body
This commit is contained in:
@@ -34,6 +34,7 @@ import okhttp3.HttpUrl;
|
|||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
import okhttp3.ResponseBody;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -60,7 +61,10 @@ public class HiscoreClient
|
|||||||
|
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
|
|
||||||
InputStream in = response.body().byteStream();
|
try (ResponseBody body = response.body())
|
||||||
return gson.fromJson(new InputStreamReader(in), HiscoreResult.class);
|
{
|
||||||
|
InputStream in = body.byteStream();
|
||||||
|
return gson.fromJson(new InputStreamReader(in), HiscoreResult.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import okhttp3.HttpUrl;
|
|||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
import okhttp3.ResponseBody;
|
||||||
import org.apache.commons.csv.CSVFormat;
|
import org.apache.commons.csv.CSVFormat;
|
||||||
import org.apache.commons.csv.CSVParser;
|
import org.apache.commons.csv.CSVParser;
|
||||||
import org.apache.commons.csv.CSVRecord;
|
import org.apache.commons.csv.CSVRecord;
|
||||||
@@ -53,8 +54,14 @@ public class HiscoreService
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
Response response = client.newCall(request).execute();
|
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();
|
HiscoreResultBuilder hiscoreBuilder = new HiscoreResultBuilder();
|
||||||
hiscoreBuilder.setPlayer(username);
|
hiscoreBuilder.setPlayer(username);
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import okhttp3.HttpUrl;
|
|||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
import okhttp3.ResponseBody;
|
||||||
|
|
||||||
public class WorldsService
|
public class WorldsService
|
||||||
{
|
{
|
||||||
@@ -50,8 +51,12 @@ public class WorldsService
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
Response response = client.newCall(request).execute();
|
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<>();
|
List<World> worlds = new ArrayList<>();
|
||||||
ByteBuffer buf = ByteBuffer.wrap(b);
|
ByteBuffer buf = ByteBuffer.wrap(b);
|
||||||
|
|||||||
Reference in New Issue
Block a user