package jetbrains.mps.baseLanguage.unitTest.execution.server; /*Generated by MPS */ import java.io.FilterOutputStream; import java.io.PrintStream; import java.io.IOException; public class CommandOutputStream extends FilterOutputStream { private final PrintStream myPrintStream; private int myLastChar; public CommandOutputStream(PrintStream out) { super(out); this.myPrintStream = out; } @Override public void write(int b) throws IOException { this.myLastChar = b; this.out.write(b); } @Override public void write(byte[] b) throws IOException { if (b.length > 0) { this.myLastChar = b[b.length - 1]; } this.out.write(b); } @Override public void write(byte[] b, int off, int len) throws IOException { int lastIndex = off + len - 1; if (0 <= lastIndex && lastIndex < b.length) { this.myLastChar = b[lastIndex]; } this.out.write(b, off, len); } public void writeCommand(String command) { if (this.myLastChar != '\n' && this.myLastChar != '\r') { this.myPrintStream.println(); } this.myPrintStream.println(command); this.myLastChar = '\n'; } public void flushSafe() { try { flush(); } catch (IOException e) { } } public PrintStream getOldStream() { return myPrintStream; } }