Added DebugPaste command, to upload settings.yml and latest.log

This commit is contained in:
Sauilitired
2015-07-18 19:18:15 +02:00
parent ea8f026105
commit 514cb8134a
5 changed files with 96 additions and 64 deletions

View File

@ -0,0 +1,53 @@
package com.intellectualcrafters.plot.util;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class HastebinUtility {
public static final String BIN_URL = "http://hastebin.com/documents", USER_AGENT = "Mozilla/5.0";
public static final Pattern PATTERN = Pattern.compile("\\{\"key\":\"([\\S\\s]*)\"\\}");
public static String upload(final File file) throws IOException {
StringBuilder content = new StringBuilder();
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
content.append(line).append("\n");
}
reader.close();
URL url = new URL(BIN_URL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("User-Agent", USER_AGENT);
connection.setDoOutput(true);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.writeUTF(content.toString());
outputStream.flush();
outputStream.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
Matcher matcher = PATTERN.matcher(response.toString());
if (matcher.matches()) {
return "http://hastebin.com/" + matcher.group(1);
} else {
throw new RuntimeException("Coldn't read response!");
}
}
}