mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-26 02:15:31 +02:00
Change the OuputStream for the writ() with
and Writer. and clear the buffer on flush.
This commit is contained in:
parent
8ec4917904
commit
90cba2d346
1 changed files with 27 additions and 15 deletions
|
@ -6,7 +6,7 @@
|
||||||
package org.eclipse.cdt.debug.mi.core;
|
package org.eclipse.cdt.debug.mi.core;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.Writer;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.mi.core.command.CLICommand;
|
import org.eclipse.cdt.debug.mi.core.command.CLICommand;
|
||||||
import org.eclipse.debug.core.model.IStreamMonitor;
|
import org.eclipse.debug.core.model.IStreamMonitor;
|
||||||
|
@ -19,7 +19,8 @@ public class GDBStreamsProxy implements IStreamsProxy {
|
||||||
MISession session;
|
MISession session;
|
||||||
GDBStreamMonitor miConsole;
|
GDBStreamMonitor miConsole;
|
||||||
GDBStreamMonitor miLog;
|
GDBStreamMonitor miLog;
|
||||||
OutputStream out;
|
Writer out;
|
||||||
|
int offset;
|
||||||
|
|
||||||
public GDBStreamsProxy(MISession ses) {
|
public GDBStreamsProxy(MISession ses) {
|
||||||
session = ses;
|
session = ses;
|
||||||
|
@ -52,31 +53,42 @@ public class GDBStreamsProxy implements IStreamsProxy {
|
||||||
*/
|
*/
|
||||||
public void write(String input) throws IOException {
|
public void write(String input) throws IOException {
|
||||||
if (out == null) {
|
if (out == null) {
|
||||||
out = new OutputStream() {
|
out = new Writer() {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
public void write(int b) throws IOException {
|
public void write(char[] cbuf, int off, int len) throws IOException {
|
||||||
buf.append((char)b);
|
for (int i = off; i < cbuf.length && len > 0; i++, len--) {
|
||||||
if (b == '\n') {
|
if (cbuf[i] == '\n') {
|
||||||
flush();
|
flush();
|
||||||
|
} else {
|
||||||
|
buf.append(cbuf[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void close () {
|
||||||
|
buf.setLength(0);
|
||||||
|
}
|
||||||
|
|
||||||
// Encapsulate the string sent to gdb in a fake
|
// Encapsulate the string sent to gdb in a fake
|
||||||
// command and post it to the TxThread.
|
// command and post it to the TxThread.
|
||||||
public void flush() throws IOException {
|
public void flush() throws IOException {
|
||||||
CLICommand cmd = new CLICommand(buf.toString()) {
|
CLICommand cmd = new CLICommand(buf.toString());
|
||||||
public void setToken(int token) {
|
buf.setLength(0);
|
||||||
token = token;
|
|
||||||
// override to do nothing;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
try {
|
try {
|
||||||
session.postCommand(cmd);
|
session.postCommand(cmd);
|
||||||
} catch (MIException e) {
|
} catch (MIException e) {
|
||||||
throw new IOException("no session");
|
// throw new IOException("no session:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
out.write(input.getBytes());
|
|
||||||
|
if (input.length() > offset) {
|
||||||
|
input = input.substring(offset);
|
||||||
|
offset += input.length();
|
||||||
|
} else {
|
||||||
|
offset = input.length();
|
||||||
|
}
|
||||||
|
out.write(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue