diff options
author | Arne Schwabe <arne@rfc2549.org> | 2022-03-21 14:21:55 +0100 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2022-03-21 14:21:55 +0100 |
commit | 18934d562773b552c9f5c124b04c496c89732124 (patch) | |
tree | 30ae87b0851d586a221c1d6f45d4eba95df4997d | |
parent | f62f890330a92bb895e68069bc8c340a307f1eae (diff) |
Replace CompletableFuture with FutureTask to support API < 24 (closes #1471)
-rw-r--r-- | main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java index 5ce8d864..51fc58eb 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java +++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java @@ -20,8 +20,11 @@ import java.util.Collections; import java.util.Date;
import java.util.LinkedList;
import java.util.Locale;
+import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -37,7 +40,9 @@ public class OpenVPNThread implements Runnable { public static final int M_NONFATAL = (1 << 5);
public static final int M_WARN = (1 << 6);
public static final int M_DEBUG = (1 << 7);
- private final CompletableFuture<OutputStream> mStreamFuture = new CompletableFuture<>();
+ private final FutureTask<OutputStream> mStreamFuture;
+ private OutputStream mOutputStream;
+
private String[] mArgv;
private Process mProcess;
private String mNativeDir;
@@ -51,6 +56,7 @@ public class OpenVPNThread implements Runnable { mNativeDir = nativelibdir;
mTmpDir = tmpdir;
mService = service;
+ mStreamFuture = new FutureTask<>(() -> mOutputStream);
}
public void stopProcess() {
@@ -131,7 +137,8 @@ public class OpenVPNThread implements Runnable { OutputStream out = mProcess.getOutputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
- mStreamFuture.complete(out);
+ mOutputStream = out;
+ mStreamFuture.run();
while (true) {
String logline = br.readLine();
|