From 981a12e349fb572a6033c96894529dea4d57a892 Mon Sep 17 00:00:00 2001 From: "Blue (Lukas Rieger)" Date: Sun, 4 Oct 2020 12:38:09 +0200 Subject: [PATCH] Fix code stylings --- .../bluemap/common/plugin/Plugin.java | 10 ++-- .../core/webserver/HttpConnection.java | 50 +++++++++---------- .../bluemap/core/webserver/WebServer.java | 2 +- .../bluecolored/bluemap/cli/BlueMapCLI.java | 16 +++--- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Plugin.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Plugin.java index 6ae25e62..f1fac16f 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Plugin.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Plugin.java @@ -127,11 +127,11 @@ public void load() throws IOException, ParseResourceException { } webServer = new WebServer( - webServerConfig.getWebserverPort(), - webServerConfig.getWebserverMaxConnections(), - webServerConfig.getWebserverBindAdress(), - requestHandler, - false + webServerConfig.getWebserverPort(), + webServerConfig.getWebserverMaxConnections(), + webServerConfig.getWebserverBindAdress(), + requestHandler, + false ); webServer.start(); } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/webserver/HttpConnection.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/webserver/HttpConnection.java index 8af9ca47..eeca2ad4 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/webserver/HttpConnection.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/webserver/HttpConnection.java @@ -46,21 +46,21 @@ public class HttpConnection implements Runnable { private Socket connection; private InputStream in; private OutputStream out; - + private final boolean verbose; - + public HttpConnection(ServerSocket server, Socket connection, HttpRequestHandler handler, int timeout, TimeUnit timeoutUnit, boolean verbose) throws IOException { this.server = server; this.connection = connection; this.handler = handler; this.verbose = verbose; - + if (isClosed()){ throw new IOException("Socket already closed!"); } - + connection.setSoTimeout((int) timeoutUnit.toMillis(timeout)); - + in = this.connection.getInputStream(); out = this.connection.getOutputStream(); } @@ -91,42 +91,42 @@ public void run() { break; } } - + try { close(); } catch (IOException e){ Logger.global.logError("Error while closing HttpConnection!", e); } } - - private void log(HttpRequest request, HttpResponse response) { + + private void log(HttpRequest request, HttpResponse response) { DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date = new Date(); Logger.global.logInfo( - connection.getInetAddress().toString() - + " [ " - + dateFormat.format(date) - + " ] \"" - + request.getMethod() - + " " + request.getPath() - + " " + request.getVersion() - + "\" " - + response.getStatusCode().toString()); - } - + connection.getInetAddress().toString() + + " [ " + + dateFormat.format(date) + + " ] \"" + + request.getMethod() + + " " + request.getPath() + + " " + request.getVersion() + + "\" " + + response.getStatusCode().toString()); + } + private void sendResponse(HttpResponse response) throws IOException { response.write(out); out.flush(); } - + private HttpRequest acceptRequest() throws ConnectionClosedException, InvalidRequestException, IOException { return HttpRequest.read(in); } - + public boolean isClosed(){ return !connection.isBound() || connection.isClosed() || !connection.isConnected() || connection.isOutputShutdown() || connection.isInputShutdown(); } - + public void close() throws IOException { try { in.close(); @@ -138,13 +138,13 @@ public void close() throws IOException { } } } - + public static class ConnectionClosedException extends IOException { private static final long serialVersionUID = 1L; } - + public static class InvalidRequestException extends IOException { private static final long serialVersionUID = 1L; } - + } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/webserver/WebServer.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/webserver/WebServer.java index 87556b6d..1725402d 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/webserver/WebServer.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/webserver/WebServer.java @@ -41,7 +41,7 @@ public class WebServer extends Thread { private final int port; private final int maxConnections; private final InetAddress bindAdress; - private final boolean verbose; + private final boolean verbose; private HttpRequestHandler handler; diff --git a/implementations/cli/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java b/implementations/cli/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java index 0ffe5480..cee88cbb 100644 --- a/implementations/cli/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java +++ b/implementations/cli/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java @@ -234,13 +234,13 @@ public void startWebserver(BlueMapService blueMap, boolean verbose) throws IOExc WebServerConfig config = blueMap.getWebServerConfig(); HttpRequestHandler requestHandler = new FileRequestHandler(config.getWebRoot().toPath(), "BlueMap v" + BlueMap.VERSION); - + WebServer webServer = new WebServer( - config.getWebserverPort(), - config.getWebserverMaxConnections(), - config.getWebserverBindAdress(), - requestHandler, - verbose + config.getWebserverPort(), + config.getWebserverMaxConnections(), + config.getWebserverBindAdress(), + requestHandler, + verbose ); webServer.start(); } @@ -375,9 +375,9 @@ private static Options createOptions() { .desc("Sets the minecraft-version, used e.g. to load resource-packs correctly. Defaults to the latest compatible version.") .build() ); - + options.addOption("w", "webserver", false, "Starts the web-server, configured in the 'webserver.conf' file"); - options.addOption("b", "verbose", false, "Causes the web-server to log requests to the console"); + options.addOption("b", "verbose", false, "Causes the web-server to log requests to the console"); options.addOption("g", "generate-webapp", false, "Generates the files for the web-app to the folder, configured in the 'render.conf' file (this is done automatically when rendering if the 'index.html' file in the webroot can't be found)"); options.addOption("s", "generate-websettings", false, "Generates the settings for the web-app, using the settings from the 'render.conf' file (this is done automatically when rendering)");