1 /*
2 * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java,v 1.15 2004/06/24 21:39:52 mbecke Exp $
3 * $Revision: 480424 $
4 * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
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.FilterInputStream;
34 import java.io.IOException;
35 import java.io.InputStream;
36
37 /**
38 * Logs all data read to the wire LOG.
39 *
40 * @author Ortwin Gl?ck
41 * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
42 * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
43 *
44 * @since 2.0
45 */
46 class WireLogInputStream extends FilterInputStream {
47
48 /** Original input stream. */
49 private InputStream in;
50
51 /** The wire log to use for writing. */
52 private Wire wire;
53
54 /**
55 * Create an instance that wraps the specified input stream.
56 * @param in The input stream.
57 * @param wire The wire log to use.
58 */
59 public WireLogInputStream(InputStream in, Wire wire) {
60 super(in);
61 this.in = in;
62 this.wire = wire;
63 }
64 /**
65 *
66 * @see java.io.InputStream#read(byte[], int, int)
67 */
68 public int read(byte[] b, int off, int len) throws IOException {
69 int l = this.in.read(b, off, len);
70 if (l > 0) {
71 wire.input(b, off, l);
72 }
73 return l;
74 }
75
76 /**
77 *
78 * @see java.io.InputStream#read()
79 */
80 public int read() throws IOException {
81 int l = this.in.read();
82 if (l > 0) {
83 wire.input(l);
84 }
85 return l;
86 }
87
88 /**
89 *
90 * @see java.io.InputStream#read(byte[])
91 */
92 public int read(byte[] b) throws IOException {
93 int l = this.in.read(b);
94 if (l > 0) {
95 wire.input(b, 0, l);
96 }
97 return l;
98 }
99 }