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 package org.apache.commons.io.input; 018 019 import java.io.FilterReader; 020 import java.io.IOException; 021 import java.io.Reader; 022 023 /** 024 * A Proxy stream which acts as expected, that is it passes the method 025 * calls on to the proxied stream and doesn't change which methods are 026 * being called. 027 * <p> 028 * It is an alternative base class to FilterReader 029 * to increase reusability, because FilterReader changes the 030 * methods being called, such as read(char[]) to read(char[], int, int). 031 * 032 * @author Stephen Colebourne 033 * @version $Id: ProxyReader.java 610010 2008-01-08 14:50:59Z niallp $ 034 */ 035 public abstract class ProxyReader extends FilterReader { 036 037 /** 038 * Constructs a new ProxyReader. 039 * 040 * @param proxy the Reader to delegate to 041 */ 042 public ProxyReader(Reader proxy) { 043 super(proxy); 044 // the proxy is stored in a protected superclass variable named 'in' 045 } 046 047 /** 048 * Invokes the delegate's <code>read()</code> method. 049 * @return the character read or -1 if the end of stream 050 * @throws IOException if an I/O error occurs 051 */ 052 public int read() throws IOException { 053 return in.read(); 054 } 055 056 /** 057 * Invokes the delegate's <code>read(char[])</code> method. 058 * @param chr the buffer to read the characters into 059 * @return the number of characters read or -1 if the end of stream 060 * @throws IOException if an I/O error occurs 061 */ 062 public int read(char[] chr) throws IOException { 063 return in.read(chr); 064 } 065 066 /** 067 * Invokes the delegate's <code>read(char[], int, int)</code> method. 068 * @param chr the buffer to read the characters into 069 * @param st The start offset 070 * @param end The number of bytes to read 071 * @return the number of characters read or -1 if the end of stream 072 * @throws IOException if an I/O error occurs 073 */ 074 public int read(char[] chr, int st, int end) throws IOException { 075 return in.read(chr, st, end); 076 } 077 078 /** 079 * Invokes the delegate's <code>skip(long)</code> method. 080 * @param ln the number of bytes to skip 081 * @return the number of bytes to skipped or -1 if the end of stream 082 * @throws IOException if an I/O error occurs 083 */ 084 public long skip(long ln) throws IOException { 085 return in.skip(ln); 086 } 087 088 /** 089 * Invokes the delegate's <code>ready()</code> method. 090 * @return true if the stream is ready to be read 091 * @throws IOException if an I/O error occurs 092 */ 093 public boolean ready() throws IOException { 094 return in.ready(); 095 } 096 097 /** 098 * Invokes the delegate's <code>close()</code> method. 099 * @throws IOException if an I/O error occurs 100 */ 101 public void close() throws IOException { 102 in.close(); 103 } 104 105 /** 106 * Invokes the delegate's <code>mark(int)</code> method. 107 * @param idx read ahead limit 108 * @throws IOException if an I/O error occurs 109 */ 110 public synchronized void mark(int idx) throws IOException { 111 in.mark(idx); 112 } 113 114 /** 115 * Invokes the delegate's <code>reset()</code> method. 116 * @throws IOException if an I/O error occurs 117 */ 118 public synchronized void reset() throws IOException { 119 in.reset(); 120 } 121 122 /** 123 * Invokes the delegate's <code>markSupported()</code> method. 124 * @return true if mark is supported, otherwise false 125 */ 126 public boolean markSupported() { 127 return in.markSupported(); 128 } 129 130 }