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 package org.apache.hc.client5.http.impl.io;
29
30 import java.io.IOException;
31 import java.io.OutputStream;
32
33 import org.apache.hc.client5.http.impl.Wire;
34
35 class LoggingOutputStream extends OutputStream {
36
37 private final OutputStream out;
38 private final Wire wire;
39
40 public LoggingOutputStream(final OutputStream out, final Wire wire) {
41 super();
42 this.out = out;
43 this.wire = wire;
44 }
45
46 @Override
47 public void write(final int b) throws IOException {
48 try {
49 out.write(b);
50 wire.output(b);
51 } catch (final IOException ex) {
52 wire.output("[write] I/O error: " + ex.getMessage());
53 throw ex;
54 }
55 }
56
57 @Override
58 public void write(final byte[] b) throws IOException {
59 try {
60 wire.output(b);
61 out.write(b);
62 } catch (final IOException ex) {
63 wire.output("[write] I/O error: " + ex.getMessage());
64 throw ex;
65 }
66 }
67
68 @Override
69 public void write(final byte[] b, final int off, final int len) throws IOException {
70 try {
71 wire.output(b, off, len);
72 out.write(b, off, len);
73 } catch (final IOException ex) {
74 wire.output("[write] I/O error: " + ex.getMessage());
75 throw ex;
76 }
77 }
78
79 @Override
80 public void flush() throws IOException {
81 try {
82 out.flush();
83 } catch (final IOException ex) {
84 wire.output("[flush] I/O error: " + ex.getMessage());
85 throw ex;
86 }
87 }
88
89 @Override
90 public void close() throws IOException {
91 try {
92 out.close();
93 } catch (final IOException ex) {
94 wire.output("[close] I/O error: " + ex.getMessage());
95 throw ex;
96 }
97 }
98
99 }