1 /*
2 * Copyright (c) 2015, 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 */
167 }
168
169
170 static class ErrorStream extends PrintStream {
171
172 static AtomicBoolean forward = new AtomicBoolean();
173 ByteArrayOutputStream out;
174 String saved = "";
175 public ErrorStream(ByteArrayOutputStream out) {
176 super(out);
177 this.out = out;
178 }
179
180 @Override
181 public void write(int b) {
182 super.write(b);
183 if (forward.get()) err.write(b);
184 }
185
186 @Override
187 public void write(byte[] b) throws IOException {
188 super.write(b);
189 if (forward.get()) err.write(b);
190 }
191
192 @Override
193 public void write(byte[] buf, int off, int len) {
194 super.write(buf, off, len);
195 if (forward.get()) err.write(buf, off, len);
196 }
197
198 public String peek() {
199 flush();
200 return out.toString();
201 }
202
203 public String drain() {
204 flush();
205 String res = out.toString();
206 out.reset();
207 return res;
|
1 /*
2 * Copyright (c) 2015, 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 */
167 }
168
169
170 static class ErrorStream extends PrintStream {
171
172 static AtomicBoolean forward = new AtomicBoolean();
173 ByteArrayOutputStream out;
174 String saved = "";
175 public ErrorStream(ByteArrayOutputStream out) {
176 super(out);
177 this.out = out;
178 }
179
180 @Override
181 public void write(int b) {
182 super.write(b);
183 if (forward.get()) err.write(b);
184 }
185
186 @Override
187 public void write(byte[] b) {
188 super.write(b);
189 if (forward.get()) err.write(b);
190 }
191
192 @Override
193 public void write(byte[] buf, int off, int len) {
194 super.write(buf, off, len);
195 if (forward.get()) err.write(buf, off, len);
196 }
197
198 public String peek() {
199 flush();
200 return out.toString();
201 }
202
203 public String drain() {
204 flush();
205 String res = out.toString();
206 out.reset();
207 return res;
|