001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.logging.log4j.io.internal; 019 020import java.io.BufferedReader; 021import java.io.IOException; 022import java.io.Reader; 023import java.nio.CharBuffer; 024 025import org.apache.logging.log4j.Level; 026import org.apache.logging.log4j.Marker; 027import org.apache.logging.log4j.spi.ExtendedLogger; 028 029/** 030 * Internal class that exists primarly to allow location calculations to work. 031 * @since 2.12 032 */ 033public class InternalBufferedReader extends BufferedReader { 034 private static final String FQCN = InternalBufferedReader.class.getName(); 035 036 public InternalBufferedReader(final Reader reader, final ExtendedLogger logger, final String fqcn, 037 final Level level, final Marker marker) { 038 super(new InternalLoggerReader(reader, logger, fqcn == null ? FQCN : fqcn, level, marker)); 039 } 040 041 public InternalBufferedReader(final Reader reader, final int size, final ExtendedLogger logger, final String fqcn, 042 final Level level, final Marker marker) { 043 super(new InternalLoggerReader(reader, logger, fqcn == null ? FQCN : fqcn, level, marker), size); 044 } 045 046 @Override 047 public void close() throws IOException { 048 super.close(); 049 } 050 051 @Override 052 public int read() throws IOException { 053 return super.read(); 054 } 055 056 @Override 057 public int read(final char[] cbuf) throws IOException { 058 return super.read(cbuf, 0, cbuf.length); 059 } 060 061 @Override 062 public int read(final char[] cbuf, final int off, final int len) throws IOException { 063 return super.read(cbuf, off, len); 064 } 065 066 @Override 067 public int read(final CharBuffer target) throws IOException { 068 final int len = target.remaining(); 069 final char[] cbuf = new char[len]; 070 final int charsRead = read(cbuf, 0, len); 071 if (charsRead > 0) { 072 target.put(cbuf, 0, charsRead); 073 } 074 return charsRead; 075 } 076 077 @Override 078 public String readLine() throws IOException { 079 return super.readLine(); 080 } 081}