From 90cba2d346d7b92445e94e3c16893fb901ef437a Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Tue, 22 Oct 2002 15:54:02 +0000 Subject: [PATCH] Change the OuputStream for the writ() with and Writer. and clear the buffer on flush. --- .../cdt/debug/mi/core/GDBStreamsProxy.java | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBStreamsProxy.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBStreamsProxy.java index f17fed9cc77..6e5fc59cc6d 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBStreamsProxy.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBStreamsProxy.java @@ -6,7 +6,7 @@ package org.eclipse.cdt.debug.mi.core; import java.io.IOException; -import java.io.OutputStream; +import java.io.Writer; import org.eclipse.cdt.debug.mi.core.command.CLICommand; import org.eclipse.debug.core.model.IStreamMonitor; @@ -19,7 +19,8 @@ public class GDBStreamsProxy implements IStreamsProxy { MISession session; GDBStreamMonitor miConsole; GDBStreamMonitor miLog; - OutputStream out; + Writer out; + int offset; public GDBStreamsProxy(MISession ses) { session = ses; @@ -52,31 +53,42 @@ public class GDBStreamsProxy implements IStreamsProxy { */ public void write(String input) throws IOException { if (out == null) { - out = new OutputStream() { + out = new Writer() { StringBuffer buf = new StringBuffer(); - public void write(int b) throws IOException { - buf.append((char)b); - if (b == '\n') { - flush(); + public void write(char[] cbuf, int off, int len) throws IOException { + for (int i = off; i < cbuf.length && len > 0; i++, len--) { + if (cbuf[i] == '\n') { + flush(); + } else { + buf.append(cbuf[i]); + } } } + + public void close () { + buf.setLength(0); + } + // Encapsulate the string sent to gdb in a fake // command and post it to the TxThread. public void flush() throws IOException { - CLICommand cmd = new CLICommand(buf.toString()) { - public void setToken(int token) { - token = token; - // override to do nothing; - } - }; + CLICommand cmd = new CLICommand(buf.toString()); + buf.setLength(0); try { session.postCommand(cmd); } 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); } }