mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-09-26 02:15:47 +00:00
Refactor and cleanup
This commit is contained in:
@@ -24,7 +24,6 @@ import lombok.extern.jackson.Jacksonized;
|
||||
import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
@@ -188,8 +187,6 @@ public class BeaconClient implements AutoCloseable {
|
||||
JsonNode node;
|
||||
try (InputStream blockIn = BeaconFormat.readBlocks(in)) {
|
||||
node = JacksonMapper.newMapper().readTree(blockIn);
|
||||
} catch (SocketException ex) {
|
||||
throw new ConnectorException("Connection to xpipe daemon closed unexpectedly", ex);
|
||||
} catch (IOException ex) {
|
||||
throw new ConnectorException("Couldn't read from socket", ex);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public class BeaconFormat {
|
||||
|
||||
private static final int SEGMENT_SIZE = 65536;
|
||||
|
||||
public static OutputStream writeBlocks(OutputStream out) throws IOException {
|
||||
public static OutputStream writeBlocks(OutputStream out) {
|
||||
return new OutputStream() {
|
||||
private final byte[] currentBytes = new byte[SEGMENT_SIZE];
|
||||
private int index;
|
||||
@@ -64,7 +64,7 @@ public class BeaconFormat {
|
||||
};
|
||||
}
|
||||
|
||||
public static InputStream readBlocks(InputStream in) throws IOException {
|
||||
public static InputStream readBlocks(InputStream in) {
|
||||
return new InputStream() {
|
||||
|
||||
private byte[] currentBytes;
|
||||
|
||||
@@ -20,7 +20,6 @@ import lombok.SneakyThrows;
|
||||
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -89,7 +88,7 @@ public class BeaconProxyImpl extends ProxyProvider {
|
||||
var inputStream = new FilterInputStream(finalClient.receiveBody()) {
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void close() throws IOException {
|
||||
public void close() {
|
||||
super.close();
|
||||
finalClient.close();
|
||||
}
|
||||
@@ -120,7 +119,7 @@ public class BeaconProxyImpl extends ProxyProvider {
|
||||
var outputStream = new FilterOutputStream(client.sendBody()) {
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void close() throws IOException {
|
||||
public void close() {
|
||||
super.close();
|
||||
finalClient.receiveResponse();
|
||||
finalClient.close();
|
||||
|
||||
@@ -25,17 +25,16 @@ public class BeaconServer {
|
||||
}
|
||||
|
||||
private static List<String> toProcessCommand(String toExec) {
|
||||
var command = OsType.getLocal().equals(OsType.WINDOWS) ? List.of("cmd", "/c", toExec) : List.of("sh", "-c", toExec);
|
||||
var command =
|
||||
OsType.getLocal().equals(OsType.WINDOWS) ? List.of("cmd", "/c", toExec) : List.of("sh", "-c", toExec);
|
||||
return command;
|
||||
}
|
||||
|
||||
public static Process tryStartCustom() throws Exception {
|
||||
var custom = BeaconConfig.getCustomDaemonCommand();
|
||||
if (custom != null) {
|
||||
var toExec = custom
|
||||
+ (BeaconConfig.getDaemonArguments() != null
|
||||
? " " + BeaconConfig.getDaemonArguments()
|
||||
: "");
|
||||
var toExec =
|
||||
custom + (BeaconConfig.getDaemonArguments() != null ? " " + BeaconConfig.getDaemonArguments() : "");
|
||||
var command = toProcessCommand(toExec);
|
||||
Process process = Runtime.getRuntime().exec(command.toArray(String[]::new));
|
||||
printDaemonOutput(process, command);
|
||||
@@ -113,7 +112,7 @@ public class BeaconServer {
|
||||
return res.isSuccess();
|
||||
}
|
||||
|
||||
public static String getDaemonDebugExecutable(String installationBase) throws Exception {
|
||||
public static String getDaemonDebugExecutable(String installationBase) {
|
||||
var osType = OsType.getLocal();
|
||||
var debug = BeaconConfig.launchDaemonInDebugMode();
|
||||
if (!debug) {
|
||||
|
||||
@@ -20,8 +20,10 @@ public class AskpassExchange implements MessageExchange {
|
||||
public static class Request implements RequestMessage {
|
||||
@NonNull
|
||||
String id;
|
||||
|
||||
@NonNull
|
||||
String request;
|
||||
|
||||
String prompt;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ public class LaunchExchange implements MessageExchange {
|
||||
@Builder
|
||||
@Value
|
||||
public static class Response implements ResponseMessage {
|
||||
@NonNull List<String> command;
|
||||
@NonNull
|
||||
List<String> command;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user