Changing file read strategy
This commit is contained in:
parent
b7e1478991
commit
66ef3badfd
@ -4,7 +4,6 @@ import java.io.IOException;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -18,25 +17,20 @@ public class ReadLogFileCommand implements WSCommand{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(WSServer wsServer, WebSocket conn, String params) {
|
public void execute(WSServer wsServer, WebSocket conn, String params) {
|
||||||
String log = null;
|
List<String> lines = null;
|
||||||
try {
|
try {
|
||||||
log = new String(Files.readAllBytes(Paths.get("logs/latest.log")), StandardCharsets.UTF_8);
|
lines = Files.readAllLines(Paths.get("logs/latest.log"), StandardCharsets.UTF_8);
|
||||||
List<Character> newLineChars = Arrays.asList('\n', '\r');
|
|
||||||
|
|
||||||
while(newLineChars.contains(log.charAt(log.length()-1)))
|
|
||||||
log = log.substring(0, log.length() - 1);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(log == null) {
|
if(lines == null) {
|
||||||
Bukkit.getLogger().info(Internationalization.getPhrase("log-read-error"));
|
Bukkit.getLogger().info(Internationalization.getPhrase("log-read-error"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wsServer.sendToClient(conn,
|
for(String line : lines)
|
||||||
new ConsoleOutput(log)
|
wsServer.sendToClient(conn, new ConsoleOutput(line));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user