View Javadoc

1   /**
2    * Copyright (C) 2010-2012 Joerg Bellmann <joerg.bellmann@googlemail.com>
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.googlecode.t7mp.util;
17  
18  import java.io.IOException;
19  import java.io.OutputStream;
20  import java.io.PrintStream;
21  
22  /**
23   * 
24   * @author Joerg Bellmann
25   * 
26   */
27  public final class CatalinaOutPrintStream extends PrintStream {
28  
29      private final PrintStream originalSystemErr;
30      private final boolean suspendConsoleOutput;
31  
32      public CatalinaOutPrintStream(PrintStream originalSystemErr, OutputStream outputStream, boolean suspendConsoleOutput)
33              throws IOException {
34          super(outputStream, true);
35          this.originalSystemErr = originalSystemErr;
36          this.suspendConsoleOutput = suspendConsoleOutput;
37      }
38  
39      public PrintStream getOriginalSystemErr() {
40          return this.originalSystemErr;
41      }
42  
43      @Override
44      public boolean checkError() {
45          return originalSystemErr.checkError() || super.checkError();
46      }
47  
48      @Override
49      public void write(int x) {
50          if (!suspendConsoleOutput) {
51              originalSystemErr.write(x);
52          }
53          super.write(x);
54      }
55  
56      @Override
57      public void write(byte[] x, int o, int l) {
58          if (!suspendConsoleOutput) {
59              originalSystemErr.write(x, o, l);
60          }
61          super.write(x, o, l);
62      }
63  
64      @Override
65      public void close() {
66          super.close();
67      }
68  
69      @Override
70      public void flush() {
71          originalSystemErr.flush();
72          super.flush();
73      }
74  
75  }