Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarin Wright2001-07-17 16:58:36 +0000
committerDarin Wright2001-07-17 16:58:36 +0000
commitbe1d81e70b3087f4363f7c6df24c8a1314f421e5 (patch)
tree1d0f0fb3868b1c3f734e8c72e94d4f5826a30f04
parent5c83dd254d3eaab6f411ed4f345fbe3b9a01e42a (diff)
downloadeclipse.platform.debug-be1d81e70b3087f4363f7c6df24c8a1314f421e5.tar.gz
eclipse.platform.debug-be1d81e70b3087f4363f7c6df24c8a1314f421e5.tar.xz
eclipse.platform.debug-be1d81e70b3087f4363f7c6df24c8a1314f421e5.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
3 files changed, 114 insertions, 7 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();
}

Back to the top