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 */
23
24 package jdk.test.lib.process;
25
26 import java.io.IOException;
27 import java.util.Arrays;
28 import java.util.List;
29 import java.util.regex.Matcher;
30 import java.util.regex.Pattern;
31
32 public final class OutputAnalyzer {
33
34 private final String stdout;
35 private final String stderr;
36 private final int exitValue;
37
38 /**
39 * Create an OutputAnalyzer, a utility class for verifying output and exit
40 * value from a Process
41 *
42 * @param process Process to analyze
43 * @throws IOException If an I/O error occurs.
44 */
45 public OutputAnalyzer(Process process) throws IOException {
46 OutputBuffer output = ProcessTools.getOutput(process);
398 }
399
400
401 /**
402 * Report summary that will help to diagnose the problem
403 * Currently includes:
404 * - standard input produced by the process under test
405 * - standard output
406 * - exit code
407 * Note: the command line is printed by the ProcessTools
408 */
409 public void reportDiagnosticSummary() {
410 String msg =
411 " stdout: [" + stdout + "];\n" +
412 " stderr: [" + stderr + "]\n" +
413 " exitValue = " + getExitValue() + "\n";
414
415 System.err.println(msg);
416 }
417
418
419 /**
420 * Get the contents of the output buffer (stdout and stderr)
421 *
422 * @return Content of the output buffer
423 */
424 public String getOutput() {
425 return stdout + stderr;
426 }
427
428 /**
429 * Get the contents of the stdout buffer
430 *
431 * @return Content of the stdout buffer
432 */
433 public String getStdout() {
434 return stdout;
435 }
436
437 /**
|
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 */
23
24 package jdk.test.lib.process;
25
26 import java.io.IOException;
27 import java.io.PrintStream;
28 import java.util.Arrays;
29 import java.util.List;
30 import java.util.regex.Matcher;
31 import java.util.regex.Pattern;
32
33 public final class OutputAnalyzer {
34
35 private final String stdout;
36 private final String stderr;
37 private final int exitValue;
38
39 /**
40 * Create an OutputAnalyzer, a utility class for verifying output and exit
41 * value from a Process
42 *
43 * @param process Process to analyze
44 * @throws IOException If an I/O error occurs.
45 */
46 public OutputAnalyzer(Process process) throws IOException {
47 OutputBuffer output = ProcessTools.getOutput(process);
399 }
400
401
402 /**
403 * Report summary that will help to diagnose the problem
404 * Currently includes:
405 * - standard input produced by the process under test
406 * - standard output
407 * - exit code
408 * Note: the command line is printed by the ProcessTools
409 */
410 public void reportDiagnosticSummary() {
411 String msg =
412 " stdout: [" + stdout + "];\n" +
413 " stderr: [" + stderr + "]\n" +
414 " exitValue = " + getExitValue() + "\n";
415
416 System.err.println(msg);
417 }
418
419 /**
420 * Print the stdout buffer to the given {@code PrintStream}.
421 *
422 * @return this OutputAnalyzer
423 */
424 public OutputAnalyzer outputTo(PrintStream out) {
425 out.println(getStdout());
426 return this;
427 }
428
429 /**
430 * Print the stderr buffer to the given {@code PrintStream}.
431 *
432 * @return this OutputAnalyzer
433 */
434 public OutputAnalyzer errorTo(PrintStream out) {
435 out.println(getStderr());
436 return this;
437 }
438
439 /**
440 * Get the contents of the output buffer (stdout and stderr)
441 *
442 * @return Content of the output buffer
443 */
444 public String getOutput() {
445 return stdout + stderr;
446 }
447
448 /**
449 * Get the contents of the stdout buffer
450 *
451 * @return Content of the stdout buffer
452 */
453 public String getStdout() {
454 return stdout;
455 }
456
457 /**
|