1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  package org.abstracthorizon.danube.support.logging;
14  
15  import java.io.IOException;
16  import java.io.OutputStream;
17  
18  
19  
20  
21  
22  
23  public class LoggingOutputStream extends OutputStream {
24  
25      
26      protected OutputStream outputStream;
27  
28      
29      protected OutputStream logOutputStream;
30  
31      
32      protected boolean logging = true;
33  
34      
35  
36  
37  
38  
39      public LoggingOutputStream(OutputStream outputStream, OutputStream logOutputStream) {
40          this.outputStream = outputStream;
41          this.logOutputStream = logOutputStream;
42      }
43  
44      
45  
46  
47  
48      public void setLogging(boolean logging) {
49          this.logging = logging;
50      }
51  
52      
53  
54  
55  
56      public boolean isLogging() {
57          return logging;
58      }
59  
60      @Override
61      public void close() throws IOException {
62           outputStream.close();
63      } 
64  
65      @Override
66      public void flush() throws IOException {
67           outputStream.flush();
68      } 
69  
70      @Override
71      public void write(byte[] b) throws IOException {
72          outputStream.write(b);
73          if (logging) { logOutputStream.write(b); }
74      }
75  
76      @Override
77      public void write(byte[] b, int off, int len) throws IOException {
78          outputStream.write(b, off, len);
79          if (logging) { logOutputStream.write(b, off, len); }
80      }
81  
82      @Override
83      public void write(int b) throws IOException {
84          outputStream.write(b);
85          if (logging) { logOutputStream.write(b); }
86      }
87  }