mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 10:36:06 +01:00
make pasting more system agnostic
This commit is contained in:
parent
e821611744
commit
676c3a2e3d
@ -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);
|
||||
}
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user