|
|
@ -4,12 +4,12 @@ import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.net.HttpURLConnection; |
|
|
|
import java.net.URL; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
import org.bukkit.Bukkit; |
|
|
|
|
|
|
|
import com.entryrise.lagassist.utils.Others; |
|
|
|
import com.google.gson.JsonObject; |
|
|
|
import com.google.gson.JsonParser; |
|
|
|
|
|
|
|
public class HTTPClient { |
|
|
|
|
|
|
@ -50,42 +50,52 @@ public class HTTPClient { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static int getMultiThread(String s) { |
|
|
|
// private static int getMultiThread(String s) {
|
|
|
|
//
|
|
|
|
// String regex = "<span style=\"font-family: Arial, Helvetica, sans-serif;font-size: 44px; font-weight: bold; color: #F48A18;\">(.*.)<\\/span>";
|
|
|
|
//
|
|
|
|
// final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
|
|
|
|
// final Matcher matcher = pattern.matcher(s);
|
|
|
|
//
|
|
|
|
// if (!matcher.find()) {
|
|
|
|
// return -1;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return Integer.valueOf(matcher.group(1));
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// private static int getSingleThread(String s) {
|
|
|
|
//
|
|
|
|
// String regex = "Single Thread Rating: <\\/strong>(.*.)<br>";
|
|
|
|
//
|
|
|
|
// final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
|
|
|
|
// final Matcher matcher = pattern.matcher(s);
|
|
|
|
//
|
|
|
|
// if (!matcher.find()) {
|
|
|
|
// return -1;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// float fl = Float.valueOf(matcher.group(1));
|
|
|
|
//
|
|
|
|
// return (int) fl;
|
|
|
|
// }
|
|
|
|
|
|
|
|
String regex = "<span style=\"font-family: Arial, Helvetica, sans-serif;font-size: 44px; font-weight: bold; color: #F48A18;\">(.*.)<\\/span>"; |
|
|
|
|
|
|
|
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); |
|
|
|
final Matcher matcher = pattern.matcher(s); |
|
|
|
|
|
|
|
if (!matcher.find()) { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
return Integer.valueOf(matcher.group(1)); |
|
|
|
public BenchResponse getBenchmark() { |
|
|
|
if (is == null) { |
|
|
|
return new BenchResponse(-1, -1, false); |
|
|
|
} |
|
|
|
|
|
|
|
private static int getSingleThread(String s) { |
|
|
|
|
|
|
|
String regex = "Single Thread Rating: <\\/strong>(.*.)<br>"; |
|
|
|
|
|
|
|
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); |
|
|
|
final Matcher matcher = pattern.matcher(s); |
|
|
|
String s = Others.readInputStreamAsString(is); |
|
|
|
|
|
|
|
if (!matcher.find()) { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
JsonObject response = new JsonParser().parse(s).getAsJsonObject(); |
|
|
|
|
|
|
|
float fl = Float.valueOf(matcher.group(1)); |
|
|
|
String status = response.get("status").getAsString(); |
|
|
|
|
|
|
|
return (int) fl; |
|
|
|
if (!status.equalsIgnoreCase("OK")) { |
|
|
|
return new BenchResponse(-1, -1, false); |
|
|
|
} |
|
|
|
|
|
|
|
public BenchResponse getBenchmark() { |
|
|
|
if (is == null) { |
|
|
|
return new BenchResponse(-1, -1); |
|
|
|
} |
|
|
|
String s = Others.readInputStreamAsString(is); |
|
|
|
return new BenchResponse(getSingleThread(s), getMultiThread(s)); |
|
|
|
return new BenchResponse(response.get("single").getAsInt(), response.get("multi").getAsInt(), true); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|