001    /* FilterReader.java -- Base class for char stream classes that filter input
002       Copyright (C) 1998, 1999, 2001, 2003, 2005  Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010     
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    
039    package java.io;
040    
041    /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
042     * "The Java Language Specification", ISBN 0-201-63451-1
043     * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
044     * Status:  Believed complete and correct.
045     */
046    
047    /**
048      * This is the common superclass of all standard classes that filter 
049      * input.  It acts as a layer on top of an underlying <code>Reader</code>
050      * and simply redirects calls made to it to the subordinate Reader
051      * instead.  Subclasses of this class perform additional filtering
052      * functions in addition to simply redirecting the call.
053      * <p>
054      * When creating a subclass of <code>FilterReader</code>, override the
055      * appropriate methods to implement the desired filtering.  However, note
056      * that the <code>read(char[])</code> method does not need to be overridden
057      * as this class redirects calls to that method to 
058      * <code>read(yte[], int, int)</code> instead of to the subordinate
059      * <code>Reader} read(yte[])</code> method.
060      *
061      * @author Aaron M. Renn (arenn@urbanophile.com)
062      * @author Warren Levy (warrenl@cygnus.com)
063      */
064    public abstract class FilterReader extends Reader
065    {
066      /**
067        * This is the subordinate <code>Reader</code> to which method calls
068        * are redirected
069        */
070      protected Reader in;
071    
072      /**
073        * Create a <code>FilterReader</code> with the specified subordinate
074        * <code>Reader</code>.
075        * The <code>lock</code> of the new <code>FilterReader</code> will be set
076        * to <code>in.lock</code>.
077        *
078        * @param in The subordinate <code>Reader</code>
079        */
080      protected FilterReader(Reader in)
081      {
082        super(in.lock);
083        this.in = in;
084      }
085    
086      /**
087        * Calls the <code>in.mark(int)</code> method.
088        *
089        * @param readlimit The parameter passed to <code>in.mark(int)</code>
090        *
091        * @exception IOException If an error occurs
092        */
093      public void mark(int readlimit) throws IOException
094      {
095        in.mark(readlimit);
096      }
097    
098      /**
099        * 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
185