View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.logging.log4j.io;
19  
20  import java.io.BufferedInputStream;
21  import java.io.IOException;
22  import java.io.InputStream;
23  import java.nio.charset.Charset;
24  
25  import org.apache.logging.log4j.Level;
26  import org.apache.logging.log4j.Marker;
27  import org.apache.logging.log4j.io.internal.InternalBufferedInputStream;
28  import org.apache.logging.log4j.spi.ExtendedLogger;
29  
30  /**
31   *
32   * @since 2.1
33   */
34  public class LoggerBufferedInputStream extends BufferedInputStream {
35      private static final String FQCN = LoggerBufferedInputStream.class.getName();
36      private InternalBufferedInputStream stream;
37  
38      protected LoggerBufferedInputStream(final InputStream in, final Charset charset, final ExtendedLogger logger,
39                                          final String fqcn, final Level level, final Marker marker) {
40          super(in);
41          this.stream = new InternalBufferedInputStream(in, charset, logger, fqcn == null ? FQCN : fqcn, level, marker);
42      }
43  
44      protected LoggerBufferedInputStream(final InputStream in, final Charset charset, final int size,
45                                          final ExtendedLogger logger, final String fqcn, final Level level,
46                                          final Marker marker) {
47          super(in);
48          this.stream = new InternalBufferedInputStream(in, charset, size, logger, fqcn == null ? FQCN : fqcn, level,
49              marker);
50      }
51  
52      @Override
53      public void close() throws IOException {
54          stream.close();
55      }
56  
57      @Override
58      public synchronized int read() throws IOException {
59          return stream.read();
60      }
61  
62      @Override
63      public int read(final byte[] b) throws IOException {
64          return stream.read(b);
65      }
66  
67      @Override
68      public synchronized int read(final byte[] b, final int off, final int len) throws IOException {
69          return stream.read(b, off, len);
70      }
71  
72      @Override
73      public String toString() {
74          return LoggerBufferedInputStream.class.getSimpleName() + stream.toString();
75      }
76  }