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.testserver;
29
30 import java.io.IOException;
31 import java.io.InputStream;
32
33 class LoggingInputStream extends InputStream {
34
35 private final InputStream in;
36 private final Wire wire;
37
38 public LoggingInputStream(final InputStream in, final Wire wire) {
39 super();
40 this.in = in;
41 this.wire = wire;
42 }
43
44 @Override
45 public int read() throws IOException {
46 final int b = in.read();
47 if (b != -1) {
48 wire.input(b);
49 }
50 return b;
51 }
52
53 @Override
54 public int read(final byte[] b) throws IOException {
55 final int bytesRead = in.read(b);
56 if (bytesRead != -1) {
57 wire.input(b, 0, bytesRead);
58 }
59 return bytesRead;
60 }
61
62 @Override
63 public int read(final byte[] b, final int off, final int len) throws IOException {
64 final int bytesRead = in.read(b, off, len);
65 if (bytesRead != -1) {
66 wire.input(b, off, bytesRead);
67 }
68 return bytesRead;
69 }
70
71 @Override
72 public long skip(final long n) throws IOException {
73 return super.skip(n);
74 }
75
76 @Override
77 public int available() throws IOException {
78 return in.available();
79 }
80
81 @Override
82 public synchronized void mark(final int readlimit) {
83 super.mark(readlimit);
84 }
85
86 @Override
87 public synchronized void reset() throws IOException {
88 super.reset();
89 }
90
91 @Override
92 public boolean markSupported() {
93 return false;
94 }
95
96 @Override
97 public void close() throws IOException {
98 in.close();
99 }
100
101 }