Path: blob/master/test/hotspot/jtreg/serviceability/tmtools/share/common/ToolResults.java
41159 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22package common;2324import java.util.List;25import java.util.stream.Collectors;2627/**28* Common results of running an executable such as the saved exit code, the29* saved stdout and stderr30*/31public class ToolResults {3233public int getExitCode() {34return exitCode;35}3637public List<String> getStdout() {38return stdout;39}4041public List<String> getStderr() {42return stderr;43}4445public String getStdoutString() {46return stdout.stream().collect(Collectors.joining(System.getProperty("line.separator")));47}4849/**50* Helper function to return a specified line from the saved stdout51*52* @return the line indexed with ndx from the saved stdout. The indexes are53* zero-based so that getStdoutLine(0) returns the first line.54*/55public String getStdoutLine(int ndx) {56return stdout.get(ndx);57}5859public ToolResults(int exitCode, List<String> stdin, List<String> stderr) {60this.exitCode = exitCode;61this.stdout = stdin;62this.stderr = stderr;63}6465public ToolResults(ToolResults rawResults) {66this(rawResults.exitCode, rawResults.stdout, rawResults.stderr);67}6869@Override70public String toString() {71StringBuilder sb = new StringBuilder();72sb.append("Exit code: ").append(exitCode).append("\n");73sb.append("stdout:");74stdout.stream().forEach((s) -> {75sb.append(s).append("\n");76});77sb.append("stderr:");78stderr.stream().forEach((s) -> {79sb.append(s).append("\n");80});81return sb.toString();82}8384private final int exitCode;85private final List<String> stdout;86private final List<String> stderr;8788}899091