1 /*
2 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
78 public String get() {
79 try {
80 future.get();
81 return buffer.toString();
82 } catch (InterruptedException e) {
83 Thread.currentThread().interrupt();
84 throw new OutputBufferException(e);
85 } catch (ExecutionException | CancellationException e) {
86 throw new OutputBufferException(e);
87 }
88 }
89 }
90
91 private final StreamTask outTask;
92 private final StreamTask errTask;
93 private final Process p;
94
95 private final void logProgress(String state) {
96 System.out.println("[" + Instant.now().toString() + "] " + state
97 + " for process " + p.pid());
98 }
99
100 private LazyOutputBuffer(Process p) {
101 this.p = p;
102 logProgress("Gathering output");
103 outTask = new StreamTask(p.getInputStream());
104 errTask = new StreamTask(p.getErrorStream());
105 }
106
107 @Override
108 public String getStdout() {
109 return outTask.get();
110 }
111
112 @Override
113 public String getStderr() {
114 return errTask.get();
115 }
116
117 @Override
|
1 /*
2 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
78 public String get() {
79 try {
80 future.get();
81 return buffer.toString();
82 } catch (InterruptedException e) {
83 Thread.currentThread().interrupt();
84 throw new OutputBufferException(e);
85 } catch (ExecutionException | CancellationException e) {
86 throw new OutputBufferException(e);
87 }
88 }
89 }
90
91 private final StreamTask outTask;
92 private final StreamTask errTask;
93 private final Process p;
94
95 private final void logProgress(String state) {
96 System.out.println("[" + Instant.now().toString() + "] " + state
97 + " for process " + p.pid());
98 System.out.flush();
99 }
100
101 private LazyOutputBuffer(Process p) {
102 this.p = p;
103 logProgress("Gathering output");
104 outTask = new StreamTask(p.getInputStream());
105 errTask = new StreamTask(p.getErrorStream());
106 }
107
108 @Override
109 public String getStdout() {
110 return outTask.get();
111 }
112
113 @Override
114 public String getStderr() {
115 return errTask.get();
116 }
117
118 @Override
|