updated shared locations
[IRC.git] / Robust / src / ClassLibrary / SSJava / FilterInputStream.java
1 /* FilterInputStream.java -- Base class for classes that filter input
2    Copyright (C) 1998, 1999, 2001, 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>InputStream</code>
50   * and simply redirects calls made to it to the subordinate InputStream
51   * instead.  Subclasses of this class perform additional filtering
52   * functions in addition to simply redirecting the call.
53   * <p>
54   * This class is not abstract.  However, since it only redirects calls
55   * to a subordinate <code>InputStream</code> without adding any functionality
56   * on top of it, this class should not be used directly.  Instead, various
57   * subclasses of this class should be used.  This is enforced with a
58   * protected constructor.  Do not try to hack around it.
59   * <p>
60   * When creating a subclass of <code>FilterInputStream</code>, override the
61   * appropriate methods to implement the desired filtering.  However, note
62   * that the <code>read(byte[])</code> method does not need to be overridden
63   * as this class redirects calls to that method to 
64   * <code>read(byte[], int, int)</code> instead of to the subordinate
65   * <code>InputStream read(byte[])</code> method.
66   *
67   * @author Aaron M. Renn (arenn@urbanophile.com)
68   * @author Warren Levy (warrenl@cygnus.com)
69   */
70 @LATTICE("IN<T")
71 @METHODDEFAULT("OUT<IN,THISLOC=OUT,GLOBALLOC=OUT")
72 public class FilterInputStream extends InputStream
73 {
74   /**
75     * This is the subordinate <code>InputStream</code> to which method calls
76     * are redirected
77     */
78   @LOC("IN") protected InputStream in;
79
80   /**
81     * Create a <code>FilterInputStream</code> with the specified subordinate
82     * <code>InputStream</code>.
83     *
84     * @param in The subordinate <code>InputStream</code>
85     */
86     protected FilterInputStream(@LOC("IN") InputStream in)
87   {
88     this.in = in;
89     in = null;
90   }
91
92   /**
93     * Calls the <code>in.mark(int)</code> method.
94     *
95     * @param readlimit The parameter passed to <code>in.mark(int)</code>
96     */
97     public void mark(@LOC("IN") int readlimit)
98   {
99     in.mark(readlimit);
100   }
101
102   /**
103     * Calls the <code>in.markSupported()</code> method.
104     *
105     * @return <code>true</code> if mark/reset is supported, <code>false</code>
106     *         otherwise
107     */
108   @RETURNLOC("OUT")
109   public boolean markSupported()
110   {
111     return in.markSupported();
112   }
113
114   /**
115     * Calls the <code>in.reset()</code> method.
116     *
117     * @exception IOException If an error occurs
118     */
119   public void reset() throws IOException
120   {
121     in.reset();
122   }
123
124   /**
125     * Calls the <code>in.available()</code> method.
126     *
127     * @return The value returned from <code>in.available()</code>
128     *
129     * @exception IOException If an error occurs
130     */
131   public int available() throws IOException
132   {
133     return in.available();
134   }
135
136   /**
137     * Calls the <code>in.skip(long)</code> method
138     *
139     * @param numBytes The requested number of bytes to skip. 
140     *
141     * @return The value returned from <code>in.skip(long)</code>
142     *
143     * @exception IOException If an error occurs
144     */
145
146     public long skip(long numBytes) throws IOException
147   {
148     return in.skip(numBytes);
149   }
150
151   /**
152     * Calls the <code>in.read()</code> method
153     *
154     * @return The value returned from <code>in.read()</code>
155     *
156     * @exception IOException If an error occurs
157     */
158
159   @RETURNLOC("OUT")
160   public int read() throws IOException
161   {
162     return in.read();
163   }
164
165   /**
166     * Calls the <code>read(byte[], int, int)</code> overloaded method.  
167     * Note that 
168     * this method does not redirect its call directly to a corresponding
169     * method in <code>in</code>.  This allows subclasses to override only the
170     * three argument version of <code>read</code>.
171     *
172     * @param buf The buffer to read bytes into
173     *
174     * @return The value retured from <code>in.read(byte[], int, int)</code>
175     *
176     * @exception IOException If an error occurs
177     */
178
179   public int read(byte[] buf) throws IOException
180   {
181     return read(buf, 0, buf.length);
182   }
183
184   /**
185     * Calls the <code>in.read(byte[], int, int)</code> method.
186     *
187     * @param buf The buffer to read bytes into
188     * @param offset The index into the buffer to start storing bytes
189     * @param len The maximum number of bytes to read.
190     *
191     * @return The value retured from <code>in.read(byte[], int, int)</code>
192     *
193     * @exception IOException If an error occurs
194     */
195
196   @RETURNLOC("OUT")
197   public int read(@LOC("OUT") byte[] buf, @LOC("IN") int offset, @LOC("IN") int len) throws IOException
198   {
199     return in.read(buf, offset, len);
200   }
201
202   /**
203     * This method closes the input stream by closing the input stream that
204     * this object is filtering.  Future attempts to access this stream may
205     * throw an exception.
206     * 
207     * @exception IOException If an error occurs
208     */
209
210   public void close() throws IOException
211   {
212     in.close();
213   }
214 }