covered up string's size insecurities with a fat bufferedreader

This commit is contained in:
PiggyPiglet 2020-03-26 11:15:16 +08:00
parent 66758b1992
commit 35738f59d9

View File

@ -164,10 +164,13 @@ public class ExpansionCloudManager {
plugin.getLogger().info("Fetching available expansion information..."); plugin.getLogger().info("Fetching available expansion information...");
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> { plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
final Map<String, CloudExpansion> data;
final String readJson = URLReader.read(API_URL); try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(API_URL).openStream()))) {
final Map<String, CloudExpansion> data = GSON.fromJson(readJson, new TypeToken<Map<String, CloudExpansion>>() { data = GSON.fromJson(reader, new TypeToken<Map<String, CloudExpansion>>() {}.getType());
}.getType()); } catch (Exception ex) {
ex.printStackTrace();
}
final List<CloudExpansion> unsorted = new ArrayList<>(); final List<CloudExpansion> unsorted = new ArrayList<>();
@ -309,24 +312,4 @@ public class ExpansionCloudManager {
}); });
} }
private static class URLReader {
static String read(String url) {
StringBuilder builder = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(url).openStream()))) {
String inputLine;
while ((inputLine = reader.readLine()) != null) {
builder.append(inputLine);
}
} catch (Exception ex) {
builder.setLength(0);
}
return builder.toString();
}
}
} }