Fix Android Studio warnings in EngineServer

This commit is contained in:
Peter Osterlund 2022-12-11 10:18:16 +01:00
parent c0963c567c
commit af1d725f27
3 changed files with 34 additions and 40 deletions

View File

@ -29,8 +29,8 @@ import java.util.Properties;
/** Manages starting and stopping PortListeners. */ /** Manages starting and stopping PortListeners. */
public class EngineServer implements ErrorHandler { public class EngineServer implements ErrorHandler {
private EngineConfig[] configs; private final EngineConfig[] configs;
private PortListener[] portListeners; private final PortListener[] portListeners;
private MainWindow window; private MainWindow window;
private EngineServer(int numEngines) { private EngineServer(int numEngines) {

View File

@ -48,8 +48,8 @@ public class MainWindow {
private JTextField[] filename; private JTextField[] filename;
private JTextField[] arguments; private JTextField[] arguments;
private EngineServer server; private final EngineServer server;
private EngineConfig[] configs; private final EngineConfig[] configs;
public MainWindow(EngineServer server, EngineConfig[] configs) { public MainWindow(EngineServer server, EngineConfig[] configs) {
this.server = server; this.server = server;

View File

@ -30,11 +30,11 @@ import java.util.ArrayList;
/** Listens to a TCP port and connects an engine process to a TCP socket. */ /** Listens to a TCP port and connects an engine process to a TCP socket. */
public class PortListener { class PortListener {
private EngineConfig config; private final EngineConfig config;
private ErrorHandler errorHandler; private final ErrorHandler errorHandler;
private Thread thread; private final Thread thread;
private ServerSocket serverSocket; private ServerSocket serverSocket;
private Socket clientSocket; private Socket clientSocket;
private Process proc; private Process proc;
@ -44,9 +44,7 @@ public class PortListener {
this.config = config; this.config = config;
this.errorHandler = errorHandler; this.errorHandler = errorHandler;
thread = new Thread() { thread = new Thread(() -> {
@Override
public void run() {
try { try {
mainLoop(); mainLoop();
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
@ -56,8 +54,7 @@ public class PortListener {
if (!shutDownFlag) if (!shutDownFlag)
reportError("IO error in background thread", ex); reportError("IO error in background thread", ex);
} }
} });
};
thread.start(); thread.start();
} }
@ -149,9 +146,7 @@ public class PortListener {
} }
private Thread forwardIO(InputStream is, OutputStream os) { private Thread forwardIO(InputStream is, OutputStream os) {
Thread t = new Thread() { Thread t = new Thread(() -> {
@Override
public void run() {
try { try {
byte[] buffer = new byte[4096]; byte[] buffer = new byte[4096];
while (true) { while (true) {
@ -168,8 +163,7 @@ public class PortListener {
Process p = proc; Process p = proc;
if (p != null) if (p != null)
p.destroyForcibly(); p.destroyForcibly();
} });
};
t.start(); t.start();
return t; return t;
} }