View Javadoc

1   /*
2    * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/oac.hc3x/trunk/src/java/org/apache/commons/httpclient/WireLogOutputStream.java $
3    * $Revision: 1425331 $
4    * $Date: 2012-12-22 18:29:41 +0000 (Sat, 22 Dec 2012) $
5    *
6    * ====================================================================
7    *
8    *  Licensed to the Apache Software Foundation (ASF) under one or more
9    *  contributor license agreements.  See the NOTICE file distributed with
10   *  this work for additional information regarding copyright ownership.
11   *  The ASF licenses this file to You under the Apache License, Version 2.0
12   *  (the "License"); you may not use this file except in compliance with
13   *  the License.  You may obtain a copy of the License at
14   *
15   *      http://www.apache.org/licenses/LICENSE-2.0
16   *
17   *  Unless required by applicable law or agreed to in writing, software
18   *  distributed under the License is distributed on an "AS IS" BASIS,
19   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   *  See the License for the specific language governing permissions and
21   *  limitations under the License.
22   * ====================================================================
23   *
24   * This software consists of voluntary contributions made by many
25   * individuals on behalf of the Apache Software Foundation.  For more
26   * information on the Apache Software Foundation, please see
27   * <http://www.apache.org/>.
28   *
29   */
30  
31  package org.apache.commons.httpclient;
32  
33  import java.io.FilterOutputStream;
34  import java.io.IOException;
35  import java.io.OutputStream;
36  
37  /***
38   * Logs all data written to the wire LOG.
39   *
40   * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
41   * 
42   * @since 2.0beta1
43   */
44  class WireLogOutputStream extends FilterOutputStream {
45  
46      /*** Original input stream. */
47      private OutputStream out;
48      
49      /*** The wire log to use. */
50      private Wire wire;
51  
52      /***
53       * Create an instance that wraps the specified output stream.
54       * @param out The output stream.
55       * @param wire The Wire log to use.
56       */
57      public WireLogOutputStream(OutputStream out, Wire wire) {
58          super(out);
59          this.out = out;
60          this.wire = wire;
61      }
62      
63      /***
64       * 
65       * @see java.io.OutputStream#write(byte[], int, int)
66       */
67      public void write(byte[] b, int off, int len) throws IOException {
68          this.out.write(b,  off,  len);
69          wire.output(b, off, len);
70      }
71  
72      /***
73       * 
74       * @see java.io.OutputStream#write()
75       */
76      public void write(int b) throws IOException {
77          this.out.write(b);
78          wire.output(b);
79      }
80  
81      /***
82       * 
83       * @see java.io.OutputStream#write(byte[])
84       */
85      public void write(byte[] b) throws IOException {
86          this.out.write(b);
87          wire.output(b);
88      }
89  }