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
;
19 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
22 private static final int JOIN_TIMEOUT
= 300;
23 private static final int BYTES_PER_KB
= 1024;
24 private final InputStreamReader fReader
;
25 private final Thread fThread
;
26 private final StringBuilder fResult
;
27 private volatile boolean fDone
;
29 public InputReader(InputStream inputStream
) {
30 fResult
= new StringBuilder();
31 fReader
= new InputStreamReader(inputStream
);
32 fThread
= new Thread() {
35 final char[] buffer
= new char[BYTES_PER_KB
];
37 int read
= fReader
.read(buffer
);
38 while (!fDone
&& (read
) > 0) {
39 fResult
.append(buffer
, 0, read
);
40 read
= fReader
.read(buffer
);
42 } catch (IOException e
) {
43 Activator
.getDefault().logError(e
.getMessage(), e
);
50 public void waitFor(IProgressMonitor monitor
) throws InterruptedException
{
51 while (fThread
.isAlive() && (monitor
== null || !monitor
.isCanceled())) {
52 fThread
.join(JOIN_TIMEOUT
);
62 public String
toString() {
63 return fResult
.toString();