aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java
diff options
context:
space:
mode:
authorMoulberry <james.jenour@student.scotch.wa.edu.au>2020-07-29 12:21:03 +1000
committerMoulberry <james.jenour@student.scotch.wa.edu.au>2020-07-29 12:21:03 +1000
commit6115246bf36fb98037ca0df2faac869eba7845c3 (patch)
tree4e659cf3d0bae323346ef251c995179c490c1115 /src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java
parent9716e11a253a370e16dd1f0bdfdd70ac21ee4102 (diff)
downloadnotenoughupdates-6115246bf36fb98037ca0df2faac869eba7845c3.tar.gz
notenoughupdates-6115246bf36fb98037ca0df2faac869eba7845c3.tar.bz2
notenoughupdates-6115246bf36fb98037ca0df2faac869eba7845c3.zip
1.11.10.5
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java b/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java
index f0a4853f..2769e18e 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java
@@ -2,6 +2,7 @@ package io.github.moulberry.notenoughupdates.util;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
+import org.apache.commons.io.IOUtils;
import java.io.BufferedReader;
import java.io.IOException;
@@ -24,7 +25,7 @@ public class HypixelApi {
*/
private Gson gson = new Gson();
- private ExecutorService es = Executors.newCachedThreadPool();
+ private ExecutorService es = Executors.newFixedThreadPool(3);
public void getHypixelApiAsync(String apiKey, String method, HashMap<String, String> args, Consumer<JsonObject> consumer) {
getHypixelApiAsync(apiKey, method, args, consumer, () -> {});
@@ -49,17 +50,10 @@ public class HypixelApi {
URLConnection connection = url.openConnection();
connection.setConnectTimeout(3000);
- try(BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
- StringBuilder builder = new StringBuilder();
- int codePoint;
- while((codePoint = reader.read()) != -1) {
- builder.append(((char)codePoint));
- }
- String response = builder.toString();
+ String response = IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8);
- JsonObject json = gson.fromJson(response, JsonObject.class);
- return json;
- }
+ JsonObject json = gson.fromJson(response, JsonObject.class);
+ return json;
}
public String generateApiUrl(String apiKey, String method, HashMap<String, String> args) {