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