Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimeon Andreev2018-12-20 08:20:59 -0500
committerAndrey Loskutov2019-01-05 12:12:01 -0500
commit343e367fc843c77c4cbc5ea46093506eb9602a47 (patch)
tree6c4803a61ef1eb1f7f9b5150e421595c609edd50
parentdf761f8f57efe71443625ed3efa1455ad74b5ebf (diff)
downloadeclipse.platform.debug-Y20190108-0410.tar.gz
eclipse.platform.debug-Y20190108-0410.tar.xz
eclipse.platform.debug-Y20190108-0410.zip
This change adds further functionality to org.eclipse.debug.internal.core.OutputStreamMonitor, which allows checking whether stream reading is done. Change-Id: Icd973a76fee9d1beeedcda988cf7a9c119f9a2b4 Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com> Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/OutputStreamMonitor.java22
1 files changed, 21 insertions, 1 deletions
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
index 330e661e4..5113d148e 100644
--- 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
@@ -17,6 +17,7 @@ package org.eclipse.debug.internal.core;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.ListenerList;
@@ -74,6 +75,8 @@ public class OutputStreamMonitor implements IFlushableStreamMonitor {
private String fEncoding;
+ private final AtomicBoolean fDone;
+
/**
* Creates an output stream monitor on the
* given stream (connected to system out or err).
@@ -85,6 +88,7 @@ public class OutputStreamMonitor implements IFlushableStreamMonitor {
fStream = new BufferedInputStream(stream, 8192);
fEncoding = encoding;
fContents= new StringBuilder();
+ fDone = new AtomicBoolean(false);
}
/* (non-Javadoc)
@@ -129,6 +133,13 @@ public class OutputStreamMonitor implements IFlushableStreamMonitor {
return fContents.toString();
}
+ private void read() {
+ try {
+ internalRead();
+ } finally {
+ fDone.set(true);
+ }
+ }
/**
* Continually reads from the stream.
* <p>
@@ -137,7 +148,7 @@ public class OutputStreamMonitor implements IFlushableStreamMonitor {
* to implement <code>Runnable</code> without publicly
* exposing a <code>run</code> method.
*/
- private void read() {
+ private void internalRead() {
lastSleep = System.currentTimeMillis();
long currentTime = lastSleep;
byte[] bytes= new byte[BUFFER_SIZE];
@@ -209,6 +220,7 @@ public class OutputStreamMonitor implements IFlushableStreamMonitor {
*/
protected void startMonitoring() {
if (fThread == null) {
+ fDone.set(false);
fThread = new Thread((Runnable) () -> read(), DebugCoreMessages.OutputStreamMonitor_label);
fThread.setDaemon(true);
fThread.setPriority(Thread.MIN_PRIORITY);
@@ -244,6 +256,14 @@ public class OutputStreamMonitor implements IFlushableStreamMonitor {
return new ContentNotifier();
}
+ /**
+ * @return {@code true} if reading the underlying stream is done.
+ * {@code false} if reading the stream has not started or is not done.
+ */
+ public boolean isReadingDone() {
+ return fDone.get();
+ }
+
class ContentNotifier implements ISafeRunnable {
private IStreamListener fListener;

Back to the top