diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/GithubPasteService.java b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/GitHubPasteService.java similarity index 88% rename from src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/GithubPasteService.java rename to src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/GitHubPasteService.java index fe7fafc4..f098e295 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/GithubPasteService.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/GitHubPasteService.java @@ -11,6 +11,7 @@ import java.io.OutputStreamWriter; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; @@ -64,14 +65,18 @@ public class GithubPasteService implements PasteService { try { URLConnection conn = url.openConnection(); conn.setDoOutput(true); - wr = new OutputStreamWriter(conn.getOutputStream()); + + // this isn't required, but is technically correct + conn.addRequestProperty("Content-Type", "application/json; charset=utf-8"); + + wr = new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8); wr.write(encodedData); wr.flush(); - rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; StringBuilder responseString = new StringBuilder(); - + // this has to be initialized AFTER the data has been flushed! + rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)); while ((line = rd.readLine()) != null) { responseString.append(line); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/HttpAPIClient.java b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/HttpAPIClient.java index 55d69c5c..962fa356 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/HttpAPIClient.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/HttpAPIClient.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; +import java.nio.charset.StandardCharsets; /** * HTTP API-client. @@ -32,11 +33,11 @@ public abstract class HttpAPIClient { StringBuilder ret = new StringBuilder(); BufferedReader reader = null; try { - reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); + reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)); while (!reader.ready()); // wait until reader is ready, may not be necessary, SUPPRESS CHECKSTYLE: EmptyStatement while (reader.ready()) { - ret.append(reader.readLine()).append('\n'); + ret.append(reader.readLine()).append(System.lineSeparator()); } } finally { if (reader != null) { diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastebinPasteService.java b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastebinPasteService.java index 7aeba797..c370c1d2 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastebinPasteService.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/PastebinPasteService.java @@ -9,6 +9,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.Map; /** @@ -65,13 +66,18 @@ public class PastebinPasteService implements PasteService { try { URLConnection conn = url.openConnection(); conn.setDoOutput(true); - wr = new OutputStreamWriter(conn.getOutputStream()); + + // this isn't required, but is technically correct + conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); + + wr = new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8); wr.write(encodedData); wr.flush(); - rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; String pastebinUrl = ""; + // this has to be initialized AFTER the data has been flushed! + rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)); while ((line = rd.readLine()) != null) { pastebinUrl = line; }