1 /* |
|
2 * CDDL HEADER START |
|
3 * |
|
4 * The contents of this file are subject to the terms of the |
|
5 * Common Development and Distribution License (the "License"). |
|
6 * You may not use this file except in compliance with the License. |
|
7 * |
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 * or http://www.opensolaris.org/os/licensing. |
|
10 * See the License for the specific language governing permissions |
|
11 * and limitations under the License. |
|
12 * |
|
13 * When distributing Covered Code, include this CDDL HEADER in each |
|
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 * If applicable, add the following below this CDDL HEADER, with the |
|
16 * fields enclosed by brackets "[]" replaced with your own identifying |
|
17 * information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 * |
|
19 * CDDL HEADER END |
|
20 */ |
|
21 |
|
22 /* |
|
23 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 package com.oracle.solaris.vp.util.misc; |
|
27 |
|
28 public class ProcessResult { |
|
29 // |
|
30 // Instance data |
|
31 // |
|
32 |
|
33 private String[] command; |
|
34 private int exitValue; |
|
35 private byte[] stdout; |
|
36 private byte[] stderr; |
|
37 |
|
38 // |
|
39 // Constructors |
|
40 // |
|
41 |
|
42 public ProcessResult(String[] command, int exitValue, byte[] stdout, |
|
43 byte[] stderr) { |
|
44 |
|
45 this.command = command; |
|
46 this.exitValue = exitValue; |
|
47 this.stdout = stdout; |
|
48 this.stderr = stderr; |
|
49 } |
|
50 |
|
51 // |
|
52 // ProcessResult methods |
|
53 // |
|
54 |
|
55 public String[] getCommand() { |
|
56 return command; |
|
57 } |
|
58 |
|
59 public int getExitValue() { |
|
60 return exitValue; |
|
61 } |
|
62 |
|
63 public byte[] getStdout() { |
|
64 return stdout; |
|
65 } |
|
66 |
|
67 public String getStdoutAsString() { |
|
68 return getAsString(stdout); |
|
69 } |
|
70 |
|
71 public String[] getStdoutAsStrings() { |
|
72 return getAsStrings(stdout); |
|
73 } |
|
74 |
|
75 public byte[] getStderr() { |
|
76 return stderr; |
|
77 } |
|
78 |
|
79 public String getStderrAsString() { |
|
80 return getAsString(stderr); |
|
81 } |
|
82 |
|
83 public String[] getStderrAsStrings() { |
|
84 return getAsStrings(stderr); |
|
85 } |
|
86 |
|
87 // |
|
88 // Private methods |
|
89 // |
|
90 |
|
91 private String getAsString(byte[] b) { |
|
92 return new String(b).replaceFirst("(\r?\n)+$", ""); |
|
93 } |
|
94 |
|
95 private String[] getAsStrings(byte[] b) { |
|
96 return new String(b).split("\r?\n", -1); |
|
97 } |
|
98 } |
|