From 66ef3badfde0c27edad6a7168de2d5f3306992c8 Mon Sep 17 00:00:00 2001 From: Carlos <28845529+mesacarlos@users.noreply.github.com> Date: Sat, 22 Feb 2020 18:37:26 +0100 Subject: [PATCH] Changing file read strategy --- .../websocket/command/ReadLogFileCommand.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/com/mesacarlos/webconsole/websocket/command/ReadLogFileCommand.java b/src/com/mesacarlos/webconsole/websocket/command/ReadLogFileCommand.java index 41e70f8..cf9879d 100644 --- a/src/com/mesacarlos/webconsole/websocket/command/ReadLogFileCommand.java +++ b/src/com/mesacarlos/webconsole/websocket/command/ReadLogFileCommand.java @@ -4,7 +4,6 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.Arrays; import java.util.List; import org.bukkit.Bukkit; @@ -18,25 +17,20 @@ public class ReadLogFileCommand implements WSCommand{ @Override public void execute(WSServer wsServer, WebSocket conn, String params) { - String log = null; + List lines = null; try { - log = new String(Files.readAllBytes(Paths.get("logs/latest.log")), StandardCharsets.UTF_8); - List newLineChars = Arrays.asList('\n', '\r'); - - while(newLineChars.contains(log.charAt(log.length()-1))) - log = log.substring(0, log.length() - 1); + lines = Files.readAllLines(Paths.get("logs/latest.log"), StandardCharsets.UTF_8); } catch (IOException e) { e.printStackTrace(); } - if(log == null) { + if(lines == null) { Bukkit.getLogger().info(Internationalization.getPhrase("log-read-error")); return; } - wsServer.sendToClient(conn, - new ConsoleOutput(log) - ); + for(String line : lines) + wsServer.sendToClient(conn, new ConsoleOutput(line)); } } \ No newline at end of file