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 package org.apache.commons.io.input; 18 19 import java.io.FilterReader; 20 import java.io.IOException; 21 import java.io.Reader; 22 23 /** 24 * A Proxy stream which acts as expected, that is it passes the method 25 * calls on to the proxied stream and doesn't change which methods are 26 * being called. 27 * <p> 28 * It is an alternative base class to FilterReader 29 * to increase reusability, because FilterReader changes the 30 * methods being called, such as read(char[]) to read(char[], int, int). 31 * 32 * @author Stephen Colebourne 33 * @version $Id: ProxyReader.java 610010 2008-01-08 14:50:59Z niallp $ 34 */ 35 public abstract class ProxyReader extends FilterReader { 36 37 /** 38 * Constructs a new ProxyReader. 39 * 40 * @param proxy the Reader to delegate to 41 */ 42 public ProxyReader(Reader proxy) { 43 super(proxy); 44 // the proxy is stored in a protected superclass variable named 'in' 45 } 46 47 /** 48 * Invokes the delegate's <code>read()</code> method. 49 * @return the character read or -1 if the end of stream 50 * @throws IOException if an I/O error occurs 51 */ 52 public int read() throws IOException { 53 return in.read(); 54 } 55 56 /** 57 * Invokes the delegate's <code>read(char[])</code> method. 58 * @param chr the buffer to read the characters into 59 * @return the number of characters read or -1 if the end of stream 60 * @throws IOException if an I/O error occurs 61 */ 62 public int read(char[] chr) throws IOException { 63 return in.read(chr); 64 } 65 66 /** 67 * Invokes the delegate's <code>read(char[], int, int)</code> method. 68 * @param chr the buffer to read the characters into 69 * @param st The start offset 70 * @param end The number of bytes to read 71 * @return the number of characters read or -1 if the end of stream 72 * @throws IOException if an I/O error occurs 73 */ 74 public int read(char[] chr, int st, int end) throws IOException { 75 return in.read(chr, st, end); 76 } 77 78 /** 79 * Invokes the delegate's <code>skip(long)</code> method. 80 * @param ln the number of bytes to skip 81 * @return the number of bytes to skipped or -1 if the end of stream 82 * @throws IOException if an I/O error occurs 83 */ 84 public long skip(long ln) throws IOException { 85 return in.skip(ln); 86 } 87 88 /** 89 * Invokes the delegate's <code>ready()</code> method. 90 * @return true if the stream is ready to be read 91 * @throws IOException if an I/O error occurs 92 */ 93 public boolean ready() throws IOException { 94 return in.ready(); 95 } 96 97 /** 98 * Invokes the delegate's <code>close()</code> method. 99 * @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 } 131