1 /**********************************************************************
2 * Copyright (c) 2014 Wind River Systems, Inc. and others
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Markus Schorn - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.remote
;
14 import java
.io
.IOException
;
15 import java
.io
.InputStream
;
16 import java
.io
.InputStreamReader
;
18 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 private final InputStreamReader fReader
;
22 private final Thread fThread
;
23 private final StringBuilder fResult
;
24 private volatile boolean fDone
;
26 public InputReader(InputStream inputStream
) {
27 fResult
= new StringBuilder();
28 fReader
= new InputStreamReader(inputStream
);
29 fThread
= new Thread() {
32 final char[] buffer
= new char[1024];
35 while (!fDone
&& (read
= fReader
.read(buffer
)) > 0) {
36 fResult
.append(buffer
, 0, read
);
38 } catch (IOException e
) {
45 public void waitFor(IProgressMonitor monitor
) throws InterruptedException
{
46 while (fThread
.isAlive() && (monitor
== null || !monitor
.isCanceled())) {
57 public String
toString() {
58 return fResult
.toString();