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.EofSensor;
34 import org.apache.http.io.HttpTransportMetrics;
35 import org.apache.http.io.SessionInputBuffer;
36 import org.apache.http.util.CharArrayBuffer;
37
38
39
40
41
42
43
44
45 @Immutable
46 @Deprecated
47 public class LoggingSessionInputBuffer implements SessionInputBuffer, EofSensor {
48
49
50 private final SessionInputBuffer in;
51
52 private final EofSensor eofSensor;
53
54
55 private final Wire wire;
56
57 private final String charset;
58
59
60
61
62
63
64
65 public LoggingSessionInputBuffer(
66 final SessionInputBuffer in, final Wire wire, final String charset) {
67 super();
68 this.in = in;
69 this.eofSensor = in instanceof EofSensor ? (EofSensor) in : null;
70 this.wire = wire;
71 this.charset = charset != null ? charset : Consts.ASCII.name();
72 }
73
74 public LoggingSessionInputBuffer(final SessionInputBuffer in, final Wire wire) {
75 this(in, wire, null);
76 }
77
78 public boolean isDataAvailable(final int timeout) throws IOException {
79 return this.in.isDataAvailable(timeout);
80 }
81
82 public int read(final byte[] b, final int off, final int len) throws IOException {
83 final int l = this.in.read(b, off, len);
84 if (this.wire.enabled() && l > 0) {
85 this.wire.input(b, off, l);
86 }
87 return l;
88 }
89
90 public int read() throws IOException {
91 final int l = this.in.read();
92 if (this.wire.enabled() && l != -1) {
93 this.wire.input(l);
94 }
95 return l;
96 }
97
98 public int read(final byte[] b) throws IOException {
99 final int l = this.in.read(b);
100 if (this.wire.enabled() && l > 0) {
101 this.wire.input(b, 0, l);
102 }
103 return l;
104 }
105
106 public String readLine() throws IOException {
107 final String s = this.in.readLine();
108 if (this.wire.enabled() && s != null) {
109 final String tmp = s + "\r\n";
110 this.wire.input(tmp.getBytes(this.charset));
111 }
112 return s;
113 }
114
115 public int readLine(final CharArrayBuffer buffer) throws IOException {
116 final int l = this.in.readLine(buffer);
117 if (this.wire.enabled() && l >= 0) {
118 final int pos = buffer.length() - l;
119 final String s = new String(buffer.buffer(), pos, l);
120 final String tmp = s + "\r\n";
121 this.wire.input(tmp.getBytes(this.charset));
122 }
123 return l;
124 }
125
126 public HttpTransportMetrics getMetrics() {
127 return this.in.getMetrics();
128 }
129
130 public boolean isEof() {
131 if (this.eofSensor != null) {
132 return this.eofSensor.isEof();
133 } else {
134 return false;
135 }
136 }
137
138 }