From 35738f59d9122e75ea8ff06f675d691ef8abff64 Mon Sep 17 00:00:00 2001 From: PiggyPiglet Date: Thu, 26 Mar 2020 11:15:16 +0800 Subject: [PATCH] covered up string's size insecurities with a fat bufferedreader --- .../cloud/ExpansionCloudManager.java | 29 ++++--------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/src/main/java/me/clip/placeholderapi/expansion/cloud/ExpansionCloudManager.java b/src/main/java/me/clip/placeholderapi/expansion/cloud/ExpansionCloudManager.java index 029e846..fd60457 100644 --- a/src/main/java/me/clip/placeholderapi/expansion/cloud/ExpansionCloudManager.java +++ b/src/main/java/me/clip/placeholderapi/expansion/cloud/ExpansionCloudManager.java @@ -164,10 +164,13 @@ public class ExpansionCloudManager { plugin.getLogger().info("Fetching available expansion information..."); plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> { + final Map data; - final String readJson = URLReader.read(API_URL); - final Map data = GSON.fromJson(readJson, new TypeToken>() { - }.getType()); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(API_URL).openStream()))) { + data = GSON.fromJson(reader, new TypeToken>() {}.getType()); + } catch (Exception ex) { + ex.printStackTrace(); + } final List 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(); - } - } - }