1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.slf4j;
20
21 import java.io.PrintStream;
22
23
24
25
26
27
28
29 class OutputChoice {
30
31 enum OutputChoiceType {
32 SYS_OUT,
33 CACHED_SYS_OUT,
34 SYS_ERR,
35 CACHED_SYS_ERR,
36 FILE;
37 }
38
39 final OutputChoiceType outputChoiceType;
40 final PrintStream targetPrintStream;
41
42 OutputChoice(OutputChoiceType outputChoiceType) {
43 if (outputChoiceType == OutputChoiceType.FILE) {
44 throw new IllegalArgumentException();
45 }
46 this.outputChoiceType = outputChoiceType;
47 if (outputChoiceType == OutputChoiceType.CACHED_SYS_OUT) {
48 this.targetPrintStream = System.out;
49 } else if (outputChoiceType == OutputChoiceType.CACHED_SYS_ERR) {
50 this.targetPrintStream = System.err;
51 } else {
52 this.targetPrintStream = null;
53 }
54 }
55
56 OutputChoice(PrintStream printStream) {
57 this.outputChoiceType = OutputChoiceType.FILE;
58 this.targetPrintStream = printStream;
59 }
60
61 PrintStream getTargetPrintStream() {
62 switch (outputChoiceType) {
63 case SYS_OUT:
64 return System.out;
65 case SYS_ERR:
66 return System.err;
67 case CACHED_SYS_ERR:
68 case CACHED_SYS_OUT:
69 case FILE:
70 return targetPrintStream;
71 default:
72 throw new IllegalArgumentException();
73 }
74 }
75 }