Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarin Wright2001-07-18 14:38:40 +0000
committerDarin Wright2001-07-18 14:38:40 +0000
commit20e9e82cd87600e590dbe69d381c94406440ebde (patch)
treea5af8d0f3451729d6307daf80b032712af061511
parentd52296b31bea43a6fd90f47578ab0c2d9d92af11 (diff)
downloadeclipse.platform.debug-20e9e82cd87600e590dbe69d381c94406440ebde.tar.gz
eclipse.platform.debug-20e9e82cd87600e590dbe69d381c94406440ebde.tar.xz
eclipse.platform.debug-20e9e82cd87600e590dbe69d381c94406440ebde.zip
1GFW4RT
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugCoreResources.properties5
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/OutputStreamMonitor.java102
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/StreamsProxy.java14
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ConsoleDocument.java4
4 files changed, 117 insertions, 8 deletions
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugCoreResources.properties b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugCoreResources.properties
index 81d42bf2f..e4a28ccf5 100644
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugCoreResources.properties
+++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugCoreResources.properties
@@ -34,6 +34,11 @@ exception_manager.error.restoring=Error restoring exceptions.
input_stream_monitor.label=Input Stream Monitor
##############################################################
+# OutputStreamMonitor
+##############################################################
+output_stream_monitor.label=Output Stream Monitor
+
+##############################################################
# Launch
##############################################################
launch.terminate_failed=Terminate failed
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/OutputStreamMonitor.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/OutputStreamMonitor.java
new file mode 100644
index 000000000..b05b0104d
--- /dev/null
+++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/OutputStreamMonitor.java
@@ -0,0 +1,102 @@
+package org.eclipse.debug.internal.core;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+/**
+ * Writes to an output stream, queueing output if the
+ * output stream is blocked.
+ */
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Vector;
+
+public class OutputStreamMonitor {
+
+ private final static String PREFIX= "output_stream_monitor.";
+ private final static String LABEL= PREFIX + "label";
+
+ protected OutputStream fStream;
+ protected Vector fQueue;
+ protected Thread fThread;
+ protected Object fLock;
+
+ /**
+ * Creates an output stream monitor on the
+ * given output stream.
+ */
+ public OutputStreamMonitor(OutputStream stream) {
+ fStream= stream;
+ fQueue= new Vector();
+ fLock= new Object();
+ }
+
+ /**
+ * Appends the given text to the stream, or
+ * queues the text to be written at a later time
+ * if the stream is blocked.
+ */
+ public void write(String text) {
+ synchronized(fLock) {
+ fQueue.add(text);
+ fLock.notifyAll();
+ }
+ }
+
+ /**
+ * Starts a <code>Thread</code> which writes the stream.
+ */
+ public void startMonitoring() {
+ if (fThread == null) {
+ fThread= new Thread(new Runnable() {
+ public void run() {
+ write();
+ }
+ }, DebugCoreUtils.getResourceString(LABEL));
+ fThread.start();
+ }
+ }
+
+ /**
+ * Causes the monitor to close all
+ * communications between it and the
+ * underlying stream.
+ */
+ public void close() {
+ if (fThread != null) {
+ Thread thread= fThread;
+ fThread= null;
+ thread.interrupt();
+ }
+ }
+
+ protected void write() {
+ while (fThread != null) {
+ writeNext();
+ }
+ }
+
+ protected void writeNext() {
+ while (!fQueue.isEmpty()) {
+ String text = (String)fQueue.firstElement();
+ fQueue.removeElementAt(0);
+ try {
+ if (fStream != null) {
+ fStream.write(text.getBytes());
+ fStream.flush();
+ }
+ } catch (IOException e) {
+ }
+ }
+ try {
+ synchronized(fLock) {
+ fLock.wait();
+ }
+ } catch (InterruptedException e) {
+ }
+ }
+}
+
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/StreamsProxy.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/StreamsProxy.java
index 904bee8c7..81f827f0e 100644
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/StreamsProxy.java
+++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/StreamsProxy.java
@@ -8,7 +8,6 @@ package org.eclipse.debug.internal.core;
import org.eclipse.debug.core.model.IStreamMonitor;
import org.eclipse.debug.core.model.IStreamsProxy;
import java.io.IOException;
-import java.io.OutputStream;
/**
* @see IStreamsProxy
@@ -23,9 +22,9 @@ public class StreamsProxy implements IStreamsProxy {
*/
protected InputStreamMonitor fErrorMonitor;
/**
- * The <code>OutputStream</code> of the <code>IProcess</code>.
+ * The monitor for the output stream (connected to standard in of the process).
*/
- protected OutputStream fOutputStream;
+ protected OutputStreamMonitor fOutputMonitor;
/**
* Records the open/closed state of communications with
* the underlying streams.
@@ -39,9 +38,10 @@ public class StreamsProxy implements IStreamsProxy {
if (process != null) {
fInputMonitor= new InputStreamMonitor(process.getInputStream());
fErrorMonitor= new InputStreamMonitor(process.getErrorStream());
- fOutputStream= process.getOutputStream();
+ fOutputMonitor= new OutputStreamMonitor(process.getOutputStream());
fInputMonitor.startMonitoring();
fErrorMonitor.startMonitoring();
+ fOutputMonitor.startMonitoring();
}
}
@@ -54,6 +54,7 @@ public class StreamsProxy implements IStreamsProxy {
fClosed= true;
fInputMonitor.close();
fErrorMonitor.close();
+ fOutputMonitor.close();
}
/**
@@ -74,9 +75,8 @@ public class StreamsProxy implements IStreamsProxy {
* @see IStreamsProxy
*/
public void write(String input) throws IOException {
- if (!fClosed && fOutputStream != null) {
- fOutputStream.write(input.getBytes());
- fOutputStream.flush();
+ if (!fClosed) {
+ fOutputMonitor.write(input);
} else {
throw new IOException();
}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ConsoleDocument.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ConsoleDocument.java
index e9ff360d2..e1a0a6989 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ConsoleDocument.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ConsoleDocument.java
@@ -25,6 +25,7 @@ public class ConsoleDocument extends AbstractDocument implements IDebugEventList
protected IProcess fProcess;
private IStreamsProxy fProxy;
private int fLastStreamWriteEnd= 0;
+ private int fLastWritePosition= 0;
private int fNewStreamWriteEnd= 0;
protected boolean fNeedsToStartReading= true;
@@ -86,7 +87,8 @@ public class ConsoleDocument extends AbstractDocument implements IDebugEventList
if (lineDelimiters[i].equals(eventText)) {
try {
String inText= event.getDocument().get();
- inText= inText.substring(fNewStreamWriteEnd, inText.length());
+ fLastWritePosition = fLastStreamWriteEnd;
+ inText= inText.substring(fLastWritePosition, inText.length());
if (inText.length() == 0) {
return;
}

Back to the top