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 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 }