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.BufferedReader;
21  import java.io.IOException;
22  import java.io.Reader;
23  import java.nio.CharBuffer;
24  
25  import org.apache.logging.log4j.Level;
26  import org.apache.logging.log4j.Marker;
27  import org.apache.logging.log4j.io.internal.InternalBufferedReader;
28  import org.apache.logging.log4j.spi.ExtendedLogger;
29  
30  /**
31   *
32   * @since 2.1
33   */
34  public class LoggerBufferedReader extends BufferedReader {
35      private static final String FQCN = LoggerBufferedReader.class.getName();
36      private final InternalBufferedReader reader;
37  
38      protected LoggerBufferedReader(final Reader reader, final ExtendedLogger logger, final String fqcn,
39                                     final Level level, final Marker marker) {
40          super(reader);
41          this.reader = new InternalBufferedReader(reader, logger, fqcn == null ? FQCN : fqcn, level, marker);
42      }
43  
44      protected LoggerBufferedReader(final Reader reader, final int size, final ExtendedLogger logger, final String fqcn,
45                                     final Level level, final Marker marker) {
46          super(reader);
47          this.reader = new InternalBufferedReader(reader, size, logger, fqcn == null ? FQCN : fqcn, level, marker);
48      }
49  
50      @Override
51      public void close() throws IOException {
52          reader.close();
53      }
54  
55      @Override
56      public int read() throws IOException {
57          return reader.read();
58      }
59  
60      @Override
61      public int read(final char[] cbuf) throws IOException {
62          return reader.read(cbuf);
63      }
64  
65      @Override
66      public int read(final char[] cbuf, final int off, final int len) throws IOException {
67          return reader.read(cbuf, off, len);
68      }
69  
70      @Override
71      public int read(final CharBuffer target) throws IOException {
72          return reader.read(target);
73      }
74  
75      @Override
76      public String readLine() throws IOException {
77          return reader.readLine();
78      }
79  }