KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > httpclient > WireLogInputStream


1 /*
2  * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java,v 1.12.2.2 2004/06/25 03:27:40 mbecke Exp $
3  * $Revision: 1.12.2.2 $
4  * $Date: 2004/06/25 03:27:40 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2004 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ====================================================================
22  *
23  * This software consists of voluntary contributions made by many
24  * individuals on behalf of the Apache Software Foundation. For more
25  * information on the Apache Software Foundation, please see
26  * <http://www.apache.org/>.
27  *
28  * [Additional notices, if required by prior licensing conditions]
29  *
30  */

31
32 package org.apache.commons.httpclient;
33
34 import java.io.FilterInputStream JavaDoc;
35 import java.io.IOException JavaDoc;
36 import java.io.InputStream JavaDoc;
37
38 /**
39  * Logs all data read to the wire LOG.
40  *
41  * @author Ortwin Gl�ck
42  * @author <a HREF="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
43  * @author <a HREF="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
44  *
45  * @since 2.0
46  */

47
48 class WireLogInputStream extends FilterInputStream JavaDoc {
49      
50     /** Original input stream. */
51     private InputStream JavaDoc in;
52
53     /** The wire log to use for writing. */
54     private Wire wire;
55     
56     /**
57      * Create an instance that wraps the specified input stream.
58      * @param in The input stream.
59      * @param wire The wire log to use.
60      */

61     public WireLogInputStream(InputStream JavaDoc in, Wire wire) {
62         super(in);
63         this.in = in;
64         this.wire = wire;
65     }
66     /**
67      *
68      * @see java.io.InputStream#read(byte[], int, int)
69      */

70     public int read(byte[] b, int off, int len) throws IOException JavaDoc {
71         int l = this.in.read(b, off, len);
72         if (l > 0) {
73             wire.input(b, off, l);
74         }
75         return l;
76     }
77
78     /**
79      *
80      * @see java.io.InputStream#read()
81      */

82     public int read() throws IOException JavaDoc {
83         int l = this.in.read();
84         if (l > 0) {
85             wire.input(l);
86         }
87         return l;
88     }
89
90     /**
91      *
92      * @see java.io.InputStream#read(byte[])
93      */

94     public int read(byte[] b) throws IOException JavaDoc {
95         int l = this.in.read(b);
96         if (l > 0) {
97             wire.input(b, 0, l);
98         }
99         return l;
100     }
101 }
102
Popular Tags