Commit 038c20ef by guo_minglei@163.com

修改运行编码格式

parent 8108428a
......@@ -10,7 +10,6 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Objects;
......@@ -108,8 +107,8 @@ public class MythJobProcess implements Callable<String>{
log.info("进程的id " + this.processId);
}
outputGobbler = new LogGobbler(new InputStreamReader(this.process.getInputStream(), StandardCharsets.UTF_8), Boolean.FALSE, 30);
errorGobbler = new LogGobbler(new InputStreamReader(this.process.getErrorStream(), StandardCharsets.UTF_8), Boolean.TRUE, 30);
outputGobbler = new LogGobbler(new InputStreamReader(this.process.getInputStream(), "GB2312"), Boolean.FALSE, 30);
errorGobbler = new LogGobbler(new InputStreamReader(this.process.getErrorStream(), "GB2312"), Boolean.TRUE, 30);
//开始获取进程的运行日志
outputGobbler.start();
errorGobbler.start();
......@@ -141,6 +140,8 @@ public class MythJobProcess implements Callable<String>{
if (this.process.isAlive()){
this.process.destroy();
}
System.out.println(outputGobbler.getRecentLog());
System.out.println(errorGobbler.getRecentLog());
return outputGobbler.getRecentLog() + "\n" + errorGobbler.getRecentLog();
}
}
......
......@@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
/**
* @description: 获取运行日志的线程
......@@ -16,12 +17,12 @@ public class LogGobbler extends Thread {
private final BufferedReader inputReader;
private final boolean isError;
private final StringBuffer buffer;
private final StringBuilder buffer;
public LogGobbler(final Reader inputReader, final boolean isError, final int bufferLines) {
this.inputReader = new BufferedReader(inputReader);
this.isError = isError;
this.buffer = new StringBuffer(bufferLines);
this.buffer = new StringBuilder(bufferLines);
}
@Override
......@@ -32,7 +33,6 @@ public class LogGobbler extends Thread {
if (line == null) {
return;
}
this.buffer.append(line + "\n");
printLog(line);
}
......@@ -62,7 +62,7 @@ public class LogGobbler extends Thread {
}
}
public String getRecentLog() {
public String getRecentLog() throws UnsupportedEncodingException {
return buffer.toString();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment