1bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook/* 2bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Licensed to the Apache Software Foundation (ASF) under one or more 3bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * contributor license agreements. See the NOTICE file distributed with 4bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * this work for additional information regarding copyright ownership. 5bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * The ASF licenses this file to You under the Apache License, Version 2.0 6bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * (the "License"); you may not use this file except in compliance with 7bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * the License. You may obtain a copy of the License at 8bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * 9bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * http://www.apache.org/licenses/LICENSE-2.0 10bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * 11bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Unless required by applicable law or agreed to in writing, software 12bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * distributed under the License is distributed on an "AS IS" BASIS, 13bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * See the License for the specific language governing permissions and 15bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * limitations under the License. 16bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook */ 17bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookpackage org.apache.commons.io.input; 18bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 19bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookimport java.io.FilterReader; 20bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookimport java.io.IOException; 21bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookimport java.io.Reader; 22bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 23bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook/** 24bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * A Proxy stream which acts as expected, that is it passes the method 25bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * calls on to the proxied stream and doesn't change which methods are 26bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * being called. 27bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * <p> 28bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * It is an alternative base class to FilterReader 29bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * to increase reusability, because FilterReader changes the 30bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * methods being called, such as read(char[]) to read(char[], int, int). 31bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * 32bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @author Stephen Colebourne 33bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @version $Id: ProxyReader.java 610010 2008-01-08 14:50:59Z niallp $ 34bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook */ 35bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookpublic abstract class ProxyReader extends FilterReader { 36bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 37bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook /** 38bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Constructs a new ProxyReader. 39bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * 40bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @param proxy the Reader to delegate to 41bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook */ 42bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook public ProxyReader(Reader proxy) { 43bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook super(proxy); 44bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook // the proxy is stored in a protected superclass variable named 'in' 45bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook } 46bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 47bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook /** 48bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Invokes the delegate's <code>read()</code> method. 49bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @return the character read or -1 if the end of stream 50bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @throws IOException if an I/O error occurs 51bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook */ 52bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook public int read() throws IOException { 53bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook return in.read(); 54bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook } 55bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 56bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook /** 57bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Invokes the delegate's <code>read(char[])</code> method. 58bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @param chr the buffer to read the characters into 59bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @return the number of characters read or -1 if the end of stream 60bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @throws IOException if an I/O error occurs 61bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook */ 62bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook public int read(char[] chr) throws IOException { 63bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook return in.read(chr); 64bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook } 65bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 66bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook /** 67bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Invokes the delegate's <code>read(char[], int, int)</code> method. 68bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @param chr the buffer to read the characters into 69bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @param st The start offset 70bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @param end The number of bytes to read 71bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @return the number of characters read or -1 if the end of stream 72bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @throws IOException if an I/O error occurs 73bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook */ 74bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook public int read(char[] chr, int st, int end) throws IOException { 75bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook return in.read(chr, st, end); 76bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook } 77bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 78bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook /** 79bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Invokes the delegate's <code>skip(long)</code> method. 80bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @param ln the number of bytes to skip 81bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @return the number of bytes to skipped or -1 if the end of stream 82bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @throws IOException if an I/O error occurs 83bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook */ 84bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook public long skip(long ln) throws IOException { 85bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook return in.skip(ln); 86bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook } 87bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 88bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook /** 89bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Invokes the delegate's <code>ready()</code> method. 90bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @return true if the stream is ready to be read 91bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @throws IOException if an I/O error occurs 92bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook */ 93bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook public boolean ready() throws IOException { 94bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook return in.ready(); 95bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook } 96bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 97bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook /** 98bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Invokes the delegate's <code>close()</code> method. 99bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @throws IOException if an I/O error occurs 100bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook */ 101bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook public void close() throws IOException { 102bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook in.close(); 103bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook } 104bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 105bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook /** 106bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Invokes the delegate's <code>mark(int)</code> method. 107bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @param idx read ahead limit 108bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @throws IOException if an I/O error occurs 109bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook */ 110bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook public synchronized void mark(int idx) throws IOException { 111bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook in.mark(idx); 112bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook } 113bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 114bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook /** 115bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Invokes the delegate's <code>reset()</code> method. 116bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @throws IOException if an I/O error occurs 117bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook */ 118bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook public synchronized void reset() throws IOException { 119bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook in.reset(); 120bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook } 121bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 122bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook /** 123bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Invokes the delegate's <code>markSupported()</code> method. 124bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @return true if mark is supported, otherwise false 125bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook */ 126bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook public boolean markSupported() { 127bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook return in.markSupported(); 128bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook } 129bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 130bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook} 131