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 package org.apache.http.impl.conn;
28
29 import java.io.IOException;
30
31 import org.apache.http.Consts;
32 import org.apache.http.annotation.Immutable;
33 import org.apache.http.io.HttpTransportMetrics;
34 import org.apache.http.io.SessionOutputBuffer;
35 import org.apache.http.util.CharArrayBuffer;
36
37
38
39
40
41
42
43 @Immutable
44 public class LoggingSessionOutputBuffer implements SessionOutputBuffer {
45
46
47 private final SessionOutputBuffer out;
48
49
50 private final Wire wire;
51
52 private final String charset;
53
54
55
56
57
58
59
60 public LoggingSessionOutputBuffer(
61 final SessionOutputBuffer out, final Wire wire, final String charset) {
62 super();
63 this.out = out;
64 this.wire = wire;
65 this.charset = charset != null ? charset : Consts.ASCII.name();
66 }
67
68 public LoggingSessionOutputBuffer(final SessionOutputBuffer out, final Wire wire) {
69 this(out, wire, null);
70 }
71
72 public void write(final byte[] b, final int off, final int len) throws IOException {
73 this.out.write(b, off, len);
74 if (this.wire.enabled()) {
75 this.wire.output(b, off, len);
76 }
77 }
78
79 public void write(final int b) throws IOException {
80 this.out.write(b);
81 if (this.wire.enabled()) {
82 this.wire.output(b);
83 }
84 }
85
86 public void write(final byte[] b) throws IOException {
87 this.out.write(b);
88 if (this.wire.enabled()) {
89 this.wire.output(b);
90 }
91 }
92
93 public void flush() throws IOException {
94 this.out.flush();
95 }
96
97 public void writeLine(final CharArrayBuffer buffer) throws IOException {
98 this.out.writeLine(buffer);
99 if (this.wire.enabled()) {
100 final String s = new String(buffer.buffer(), 0, buffer.length());
101 final String tmp = s + "\r\n";
102 this.wire.output(tmp.getBytes(this.charset));
103 }
104 }
105
106 public void writeLine(final String s) throws IOException {
107 this.out.writeLine(s);
108 if (this.wire.enabled()) {
109 final String tmp = s + "\r\n";
110 this.wire.output(tmp.getBytes(this.charset));
111 }
112 }
113
114 public HttpTransportMetrics getMetrics() {
115 return this.out.getMetrics();
116 }
117
118 }