From e5ae0426940fd78b98b7bf9c5eecf20f02341f1f Mon Sep 17 00:00:00 2001 From: rusefi Date: Wed, 22 Jul 2020 17:42:16 -0400 Subject: [PATCH] proxy progress --- .../main/java/com/rusefi/io/tcp/TcpIoStream.java | 15 +++++++++++++-- .../java/com/rusefi/tools/online/ProxyClient.java | 2 ++ .../src/main/java/com/rusefi/shared/FileUtil.java | 15 +++++++++++---- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/java_console/io/src/main/java/com/rusefi/io/tcp/TcpIoStream.java b/java_console/io/src/main/java/com/rusefi/io/tcp/TcpIoStream.java index 3a81610baa..fbea5e9430 100644 --- a/java_console/io/src/main/java/com/rusefi/io/tcp/TcpIoStream.java +++ b/java_console/io/src/main/java/com/rusefi/io/tcp/TcpIoStream.java @@ -5,6 +5,8 @@ import com.opensr5.io.DataListener; import com.rusefi.binaryprotocol.IncomingDataBuffer; import com.rusefi.io.ByteReader; import com.rusefi.io.serial.AbstractIoStream; +import com.rusefi.shared.FileUtil; +import org.jetbrains.annotations.NotNull; import java.io.BufferedInputStream; import java.io.IOException; @@ -21,6 +23,8 @@ public class TcpIoStream extends AbstractIoStream { private final OutputStream output; private final Logger logger; private final String loggingPrefix; + @NotNull + private final Socket socket; private final IncomingDataBuffer dataBuffer; public TcpIoStream(Logger logger, Socket socket) throws IOException { @@ -29,11 +33,12 @@ public class TcpIoStream extends AbstractIoStream { public TcpIoStream(String loggingPrefix, Logger logger, Socket socket) throws IOException { this.loggingPrefix = loggingPrefix; + if (socket == null) + throw new NullPointerException("socket"); + this.socket = socket; InputStream input = new BufferedInputStream(socket.getInputStream()); OutputStream output = socket.getOutputStream(); this.logger = logger; - if (input == null) - throw new NullPointerException("input"); if (output == null) throw new NullPointerException("output"); this.output = output; @@ -41,6 +46,12 @@ public class TcpIoStream extends AbstractIoStream { this.dataBuffer = IncomingDataBuffer.createDataBuffer(loggingPrefix, this, logger); } + @Override + public void close() { + super.close(); + FileUtil.close(socket); + } + @Override public String getLoggingPrefix() { return loggingPrefix; diff --git a/java_console/io/src/main/java/com/rusefi/tools/online/ProxyClient.java b/java_console/io/src/main/java/com/rusefi/tools/online/ProxyClient.java index d81e6a0cbb..d7aa18e6b8 100644 --- a/java_console/io/src/main/java/com/rusefi/tools/online/ProxyClient.java +++ b/java_console/io/src/main/java/com/rusefi/tools/online/ProxyClient.java @@ -15,6 +15,8 @@ import java.util.List; public class ProxyClient { public static final String LIST_CONTROLLERS_PATH = "/list_controllers"; public static final String LIST_APPLICATIONS_PATH = "/list_applications"; + public static final String VERSION_PATH = "/version"; + public static final String BACKEND_VERSION = "0.0001"; public static List getOnlineApplications(int httpPort) throws IOException { return getOnlineApplications(HttpUtil.RUSEFI_PROXY_JSON_API_PREFIX + ":" + httpPort + LIST_CONTROLLERS_PATH); diff --git a/java_console/shared_io/src/main/java/com/rusefi/shared/FileUtil.java b/java_console/shared_io/src/main/java/com/rusefi/shared/FileUtil.java index 9dd2965baf..033b66c919 100644 --- a/java_console/shared_io/src/main/java/com/rusefi/shared/FileUtil.java +++ b/java_console/shared_io/src/main/java/com/rusefi/shared/FileUtil.java @@ -1,9 +1,6 @@ package com.rusefi.shared; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; +import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -54,4 +51,14 @@ public class FileUtil { return destFile; } + + public static void close(Closeable closeable) { + if (closeable != null) { + try { + closeable.close(); + } catch (IOException ignored) { + // ignored + } + } + } }