View Javadoc

1   /*
2    * Copyright (c) 2004-2007 Creative Sphere Limited.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *
10   *   Creative Sphere - initial API and implementation
11   *
12   */
13  package org.abstracthorizon.danube.support.logging;
14  
15  import java.io.IOException;
16  import java.io.OutputStream;
17  
18  /**
19   * Output stream for logging showing directional marks "<".
20   * Given output stream is duplicated to log stream.
21   *
22   * @author Daniel Sendula
23   */
24  public class DirectionalLoggingOutputStream extends LoggingOutputStream {
25  
26      /** Internal flag to show when to output directional char */
27      protected boolean flag = true;
28  
29      /**
30       * Constructor
31       * @param outputStream output stream
32       * @param logOutputStream log output stream
33       */
34      public DirectionalLoggingOutputStream(OutputStream outputStream, OutputStream logOutputStream) {
35          super(outputStream, logOutputStream);
36      }
37  
38      @Override
39      public void write(byte[] b) throws IOException {
40          write(b, 0, b.length);
41      }
42  
43      @Override
44      public void write(byte[] b, int off, int len) throws IOException {
45          outputStream.write(b, off, len);
46          if (logging) { flag = DirectionalLoggingInputStream.output(flag, logOutputStream, '<', b, off, len); }
47      }
48  
49      @Override
50      public void write(int b) throws IOException {
51          outputStream.write(b);
52          if (logging) { flag = DirectionalLoggingInputStream.output(flag, logOutputStream, '<', b);  }
53      }
54  
55  }