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.http.impl.conn;
29
30 import java.io.ByteArrayInputStream;
31 import java.io.IOException;
32 import java.io.InputStream;
33 import java.nio.charset.Charset;
34 import java.nio.charset.CharsetDecoder;
35
36 import org.apache.http.config.MessageConstraints;
37 import org.apache.http.impl.io.HttpTransportMetricsImpl;
38 import org.apache.http.impl.io.SessionInputBufferImpl;
39
40
41
42
43 public class SessionInputBufferMock extends SessionInputBufferImpl {
44
45 public static final int BUFFER_SIZE = 16;
46
47 public SessionInputBufferMock(
48 final InputStream inStream,
49 final int bufferSize,
50 final MessageConstraints constrains,
51 final CharsetDecoder decoder) {
52 super(new HttpTransportMetricsImpl(), bufferSize, -1, constrains, decoder);
53 bind(inStream);
54 }
55
56 public SessionInputBufferMock(
57 final InputStream inStream,
58 final int bufferSize) {
59 this(inStream, bufferSize, null, null);
60 }
61
62 public SessionInputBufferMock(
63 final byte[] bytes,
64 final int bufferSize,
65 final MessageConstraints constrains,
66 final CharsetDecoder decoder) {
67 this(new ByteArrayInputStream(bytes), bufferSize, constrains, decoder);
68 }
69
70 public SessionInputBufferMock(
71 final byte[] bytes,
72 final int bufferSize,
73 final MessageConstraints constrains) {
74 this(new ByteArrayInputStream(bytes), bufferSize, constrains, null);
75 }
76
77 public SessionInputBufferMock(
78 final byte[] bytes,
79 final int bufferSize) {
80 this(new ByteArrayInputStream(bytes), bufferSize);
81 }
82
83 public SessionInputBufferMock(
84 final byte[] bytes) {
85 this(bytes, BUFFER_SIZE);
86 }
87
88 public SessionInputBufferMock(
89 final byte[] bytes, final Charset charset) {
90 this(bytes, BUFFER_SIZE, null, charset != null ? charset.newDecoder() : null);
91 }
92
93 public SessionInputBufferMock(
94 final byte[] bytes,
95 final CharsetDecoder decoder) {
96 this(bytes, BUFFER_SIZE, null, decoder);
97 }
98
99 public SessionInputBufferMock(
100 final String s,
101 final Charset charset) {
102 this(s.getBytes(charset), charset);
103 }
104
105 @Override
106 public boolean isDataAvailable(final int timeout) throws IOException {
107 return true;
108 }
109
110 }