1 package org.cyclopsgroup.jmxterm.io;
2
3 import org.apache.commons.lang3.Validate;
4
5 import java.io.PrintStream;
6
7
8
9
10
11
12 public class PrintStreamCommandOutput extends CommandOutput {
13 private final PrintStream messageOutput;
14
15 private final PrintStream resultOutput;
16
17
18
19
20 public PrintStreamCommandOutput() {
21 this(System.out);
22 }
23
24
25
26
27
28
29 public PrintStreamCommandOutput(PrintStream output) {
30 this(output, System.err);
31 }
32
33
34
35
36
37 public PrintStreamCommandOutput(PrintStream resultOutput, PrintStream messageOutput) {
38 Validate.notNull(resultOutput, "Result output can't be NULL");
39 Validate.notNull(messageOutput, "Message output can't be NULL");
40 this.resultOutput = resultOutput;
41 this.messageOutput = messageOutput;
42 }
43
44 @Override
45 public void print(String output) {
46 resultOutput.print(output);
47 }
48
49 @Override
50 public void printError(Throwable e) {
51 e.printStackTrace(messageOutput);
52 }
53
54 @Override
55 public void printMessage(String message) {
56 messageOutput.println(message);
57 }
58 }