1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package org.apache.commons.httpclient;
33
34 import java.io.FilterInputStream;
35 import java.io.IOException;
36 import java.io.InputStream;
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 {
49
50 /*** Original input stream. */
51 private InputStream 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 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 {
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 {
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 {
95 int l = this.in.read(b);
96 if (l > 0) {
97 wire.input(b, 0, l);
98 }
99 return l;
100 }
101 }