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