Source for java.io.FilterReader

   1: /* FilterReader.java -- Base class for char stream classes that filter input
   2:    Copyright (C) 1998, 1999, 2001, 2003, 2005  Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10:  
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package java.io;
  40: 
  41: /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
  42:  * "The Java Language Specification", ISBN 0-201-63451-1
  43:  * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
  44:  * Status:  Believed complete and correct.
  45:  */
  46: 
  47: /**
  48:   * This is the common superclass of all standard classes that filter 
  49:   * input.  It acts as a layer on top of an underlying <code>Reader</code>
  50:   * and simply redirects calls made to it to the subordinate Reader
  51:   * instead.  Subclasses of this class perform additional filtering
  52:   * functions in addition to simply redirecting the call.
  53:   * <p>
  54:   * When creating a subclass of <code>FilterReader</code>, override the
  55:   * appropriate methods to implement the desired filtering.  However, note
  56:   * that the <code>read(char[])</code> method does not need to be overridden
  57:   * as this class redirects calls to that method to 
  58:   * <code>read(yte[], int, int)</code> instead of to the subordinate
  59:   * <code>Reader} read(yte[])</code> method.
  60:   *
  61:   * @author Aaron M. Renn (arenn@urbanophile.com)
  62:   * @author Warren Levy (warrenl@cygnus.com)
  63:   */
  64: public abstract class FilterReader extends Reader
  65: {
  66:   /**
  67:     * This is the subordinate <code>Reader</code> to which method calls
  68:     * are redirected
  69:     */
  70:   protected Reader in;
  71: 
  72:   /**
  73:     * Create a <code>FilterReader</code> with the specified subordinate
  74:     * <code>Reader</code>.
  75:     * The <code>lock</code> of the new <code>FilterReader</code> will be set
  76:     * to <code>in.lock</code>.
  77:     *
  78:     * @param in The subordinate <code>Reader</code>
  79:     */
  80:   protected FilterReader(Reader in)
  81:   {
  82:     super(in.lock);
  83:     this.in = in;
  84:   }
  85: 
  86:   /**
  87:     * Calls the <code>in.mark(int)</code> method.
  88:     *
  89:     * @param readlimit The parameter passed to <code>in.mark(int)</code>
  90:     *
  91:     * @exception IOException If an error occurs
  92:     */
  93:   public void mark(int readlimit) throws IOException
  94:   {
  95:     in.mark(readlimit);
  96:   }
  97: 
  98:   /**
  99:     * Calls the <code>in.markSupported()</code> method.
 100:     *
 101:     * @return <code>true</code> if mark/reset is supported, 
 102:     * <code>false</code> otherwise
 103:     */
 104:   public boolean markSupported()
 105:   {
 106:     return(in.markSupported());
 107:   }
 108: 
 109:   /**
 110:     * Calls the <code>in.reset()</code> method.
 111:     *
 112:     * @exception IOException If an error occurs
 113:     */
 114:   public void reset() throws IOException
 115:   {
 116:     in.reset();
 117:   }
 118: 
 119:   /**
 120:     * Calls the <code>in.read()</code> method.
 121:     *
 122:     * @return The value returned from <code>in.available()</code>
 123:     *
 124:     * @exception IOException If an error occurs
 125:     */
 126:   public boolean ready() throws IOException
 127:   {
 128:     return(in.ready());
 129:   }
 130: 
 131:   /**
 132:     * Calls the <code>in.skip(long)</code> method
 133:     *
 134:     * @param num_chars The requested number of chars to skip. 
 135:     *
 136:     * @return The value returned from <code>in.skip(long)</code>
 137:     *
 138:     * @exception IOException If an error occurs
 139:     */
 140:   public long skip(long num_chars) throws IOException
 141:   {
 142:     return(in.skip(num_chars));
 143:   }
 144: 
 145:   /**
 146:     * Calls the <code>in.read()</code> method
 147:     *
 148:     * @return The value returned from <code>in.read()</code>
 149:     *
 150:     * @exception IOException If an error occurs
 151:     */
 152:   public int read() throws IOException
 153:   {
 154:     return(in.read());
 155:   }
 156: 
 157:   /**
 158:     * Calls the <code>in.read(char[], int, int)</code> method.
 159:     *
 160:     * @param buf The buffer to read chars into
 161:     * @param offset The index into the buffer to start storing chars
 162:     * @param len The maximum number of chars to read.
 163:     *
 164:     * @return The value retured from <code>in.read(char[], int, int)</code>
 165:     *
 166:     * @exception IOException If an error occurs
 167:     */
 168:   public int read(char[] buf, int offset, int len) throws IOException
 169:   {
 170:     return(in.read(buf, offset, len));
 171:   }
 172: 
 173:   /**
 174:     * This method closes the stream by calling the <code>close()</code> method
 175:     * of the underlying stream.
 176:     *
 177:     * @exception IOException If an error occurs
 178:     */
 179:   public void close() throws IOException
 180:   {
 181:     in.close();
 182:   }
 183: 
 184: } // class FilterReader