View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.hc.core5.testing.classic;
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 void mark(final int readlimit) {
83          super.mark(readlimit);
84      }
85  
86      @Override
87      public 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 }