mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2025-02-26 17:31:23 +01:00
Fix debugpaste
This commit is contained in:
parent
60152a5b1f
commit
efc0de27d4
@ -1,14 +1,10 @@
|
|||||||
package com.boydti.fawe.util;
|
package com.boydti.fawe.util;
|
||||||
|
|
||||||
import com.boydti.fawe.object.RunnableVal;
|
import java.io.*;
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -17,15 +13,17 @@ public class HastebinUtility {
|
|||||||
public static final String BIN_URL = "http://hastebin.com/documents", USER_AGENT = "Mozilla/5.0";
|
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 final Pattern PATTERN = Pattern.compile("\\{\"key\":\"([\\S\\s]*)\"\\}");
|
||||||
|
|
||||||
public static String upload(final RunnableVal<DataOutputStream> writeTask) throws IOException {
|
public static String upload(final String string) throws IOException {
|
||||||
final URL url = new URL(BIN_URL);
|
final URL url = new URL(BIN_URL);
|
||||||
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
|
||||||
connection.setRequestMethod("POST");
|
connection.setRequestMethod("POST");
|
||||||
connection.setRequestProperty("User-Agent", USER_AGENT);
|
connection.setRequestProperty("User-Agent", USER_AGENT);
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
try (DataOutputStream os = new DataOutputStream(connection.getOutputStream())) {
|
|
||||||
writeTask.run(os);
|
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
|
||||||
|
outputStream.write(string.getBytes());
|
||||||
|
outputStream.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder response;
|
StringBuilder response;
|
||||||
@ -46,30 +44,20 @@ public class HastebinUtility {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String upload(final String s) throws IOException {
|
|
||||||
return upload(new RunnableVal<DataOutputStream>() {
|
|
||||||
@Override
|
|
||||||
public void run(DataOutputStream value) {
|
|
||||||
try {
|
|
||||||
value.writeChars(s);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String upload(final File file) throws IOException {
|
public static String upload(final File file) throws IOException {
|
||||||
final StringBuilder content = new StringBuilder();
|
final StringBuilder content = new StringBuilder();
|
||||||
|
List<String> lines = new ArrayList<>();
|
||||||
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||||
String line;
|
String line;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while ((line = reader.readLine()) != null && i++ < 1000) {
|
while ((line = reader.readLine()) != null) {
|
||||||
content.append(line).append("\n");
|
lines.add(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (int i = Math.max(0, lines.size() - 1000); i < lines.size(); i++) {
|
||||||
|
content.append(lines.get(i)).append("\n");
|
||||||
|
}
|
||||||
return upload(content.toString());
|
return upload(content.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import com.boydti.fawe.util.SetQueue;
|
|||||||
import com.boydti.fawe.util.TaskManager;
|
import com.boydti.fawe.util.TaskManager;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ForkJoinPool;
|
import java.util.concurrent.ForkJoinPool;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@ -162,6 +163,50 @@ public class TaskBuilder extends Metadatable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TaskBuilder abortIfTrue(final Runnable run) {
|
||||||
|
tasks.add(RunnableTask.adapt(new Task<Boolean, Boolean>() {
|
||||||
|
@Override
|
||||||
|
public Boolean run(Boolean previous) {
|
||||||
|
if (previous == Boolean.TRUE) run.run();
|
||||||
|
return previous == Boolean.TRUE;
|
||||||
|
}
|
||||||
|
}, TaskType.ABORT));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TaskBuilder abortIfNull(final Runnable run) {
|
||||||
|
tasks.add(RunnableTask.adapt(new Task<Boolean, Object>() {
|
||||||
|
@Override
|
||||||
|
public Boolean run(Object previous) {
|
||||||
|
if (previous == null) run.run();
|
||||||
|
return previous == null;
|
||||||
|
}
|
||||||
|
}, TaskType.ABORT));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TaskBuilder abortIfEqual(final Runnable run, final Object other) {
|
||||||
|
tasks.add(RunnableTask.adapt(new Task<Boolean, Object>() {
|
||||||
|
@Override
|
||||||
|
public Boolean run(Object previous) {
|
||||||
|
if (Objects.equals(previous, other)) run.run();
|
||||||
|
return Objects.equals(previous, other);
|
||||||
|
}
|
||||||
|
}, TaskType.ABORT));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TaskBuilder abortIfNotEqual(final Runnable run, final Object other) {
|
||||||
|
tasks.add(RunnableTask.adapt(new Task<Boolean, Object>() {
|
||||||
|
@Override
|
||||||
|
public Boolean run(Object previous) {
|
||||||
|
if (!Objects.equals(previous, other)) run.run();
|
||||||
|
return !Objects.equals(previous, other);
|
||||||
|
}
|
||||||
|
}, TaskType.ABORT));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Have all async tasks run on a new thread<br>
|
* Have all async tasks run on a new thread<br>
|
||||||
* - As opposed to trying to using the current thread
|
* - As opposed to trying to using the current thread
|
||||||
@ -283,15 +328,29 @@ public class TaskBuilder extends Metadatable {
|
|||||||
if (task.isAborted()) {
|
if (task.isAborted()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (TaskAbortException abort) {
|
||||||
|
return;
|
||||||
|
} catch (Throwable e1) {
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
handler.uncaughtException(Thread.currentThread(), e);
|
try {
|
||||||
|
handler.uncaughtException(Thread.currentThread(), e1);
|
||||||
|
} catch (Throwable e2) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
e2.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final class TaskAbortException extends RuntimeException {
|
||||||
|
@Override
|
||||||
|
public synchronized Throwable fillInStackTrace() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private FaweQueue queue;
|
private FaweQueue queue;
|
||||||
private long last;
|
private long last;
|
||||||
private long start;
|
private long start;
|
||||||
|
Loading…
Reference in New Issue
Block a user