Zond: проксирование SysOut/SysErr и SysIn
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
group = 'asys'
|
group = 'asys'
|
||||||
version = '0.2-SNAPSHOT'
|
version = '0.3-SNAPSHOT'
|
||||||
|
|
||||||
apply plugin: 'application'
|
apply plugin: 'application'
|
||||||
|
|
||||||
|
|||||||
@@ -64,8 +64,11 @@ public class Main {
|
|||||||
String cmdLine = Arrays.stream(args).collect(Collectors.joining(" "));
|
String cmdLine = Arrays.stream(args).collect(Collectors.joining(" "));
|
||||||
CommandLine commandLine = CommandLine.parse(cmdLine);
|
CommandLine commandLine = CommandLine.parse(cmdLine);
|
||||||
DefaultExecutor executor = new DefaultExecutor();
|
DefaultExecutor executor = new DefaultExecutor();
|
||||||
executor.setExitValue(1);
|
|
||||||
executor.setStreamHandler(new PumpStreamHandler(System.out, System.err, System.in));
|
PrintStream proxySysOut = new ProxySysOut(System.err);
|
||||||
|
InputStream proxySysIn = new ProxySysIn();
|
||||||
|
|
||||||
|
executor.setStreamHandler(new PumpStreamHandler(proxySysOut, proxySysOut, proxySysIn));
|
||||||
|
|
||||||
int resultCode = 0;
|
int resultCode = 0;
|
||||||
try {
|
try {
|
||||||
@@ -99,7 +102,8 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void log(String message){
|
public static void log(String message){
|
||||||
System.out.println("[ASys Zond] " + message);
|
System.out.println(Ansi.ansi().bg(Color.BLUE).fg(Color.WHITE)
|
||||||
|
.a("[ASys Zond] ").a(message).reset());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void startReconnect() {
|
public static void startReconnect() {
|
||||||
@@ -123,4 +127,51 @@ public class Main {
|
|||||||
tryConnect = 0;
|
tryConnect = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class ProxySysOut extends PrintStream {
|
||||||
|
final byte[] prefix = Ansi.ansi().bg(Color.YELLOW).fg(Color.BLACK).boldOff().toString().getBytes();
|
||||||
|
final byte[] suffix = Ansi.ansi().reset().toString().getBytes();
|
||||||
|
|
||||||
|
ProxySysOut(OutputStream out) {
|
||||||
|
super(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(byte[] buf, int off, int len) {
|
||||||
|
super.write(prefix, 0, prefix.length);
|
||||||
|
super.write(buf, off, len);
|
||||||
|
super.write(suffix, 0, suffix.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(int b) {
|
||||||
|
super.write(prefix, 0, prefix.length);
|
||||||
|
super.write(b);
|
||||||
|
super.write(suffix, 0, suffix.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(byte[] b) throws IOException {
|
||||||
|
super.write(prefix, 0, prefix.length);
|
||||||
|
super.write(b);
|
||||||
|
super.write(suffix, 0, suffix.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ProxySysIn extends InputStream {
|
||||||
|
@Override
|
||||||
|
public int read() throws IOException {
|
||||||
|
return System.in.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read(byte[] b) throws IOException {
|
||||||
|
return System.in.read(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read(byte[] b, int off, int len) throws IOException {
|
||||||
|
return System.in.read(b, off, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user