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