changes: now Inference engine works fine with the EyeTracking benchmark.
[IRC.git] / Robust / src / ClassLibrary / SSJava / FilterOutputStream.java
1 /* FilterOutputStream.java -- Parent class for output streams that filter
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  * Status:  Complete to version 1.1.
44  */
45
46 /**
47   * This class is the common superclass of output stream classes that 
48   * filter the output they write.  These classes typically transform the
49   * data in some way prior to writing it out to another underlying
50   * <code>OutputStream</code>.  This class simply overrides all the 
51   * methods in <code>OutputStream</code> to redirect them to the
52   * underlying stream.  Subclasses provide actual filtering.
53   *
54   * @author Aaron M. Renn (arenn@urbanophile.com)
55   * @author Tom Tromey (tromey@cygnus.com)
56   */
57 public class FilterOutputStream extends OutputStream
58 {
59   /**
60     * This is the subordinate <code>OutputStream</code> that this class
61     * redirects its method calls to.
62     */
63   protected OutputStream out;
64
65   /**
66     * This method initializes an instance of <code>FilterOutputStream</code>
67     * to write to the specified subordinate <code>OutputStream</code>.
68     *
69     * @param out The <code>OutputStream</code> to write to
70     */
71   public FilterOutputStream(OutputStream out)
72   {
73     this.out = out;
74   }
75
76   /**
77     * This method closes the underlying <code>OutputStream</code>.  Any
78     * further attempts to write to this stream may throw an exception.
79     *
80     * @exception IOException If an error occurs
81     */
82   public void close() //throws IOException
83   {
84     flush();
85     out.close();
86   }
87
88   /**
89     * This method attempt to flush all buffered output to be written to the
90     * underlying output sink.
91     *
92     * @exception IOException If an error occurs
93     */
94   public void flush() //throws IOException
95   {
96     out.flush();
97   }
98
99   /**
100     * This method writes a single byte of output to the underlying
101     * <code>OutputStream</code>.
102     *
103     * @param b The byte to write, passed as an int.
104     *
105     * @exception IOException If an error occurs
106     */
107   public void write(int b) //throws IOException
108   {
109     out.write(b);
110   }
111
112   /**
113     * This method writes all the bytes in the specified array to the underlying
114     * <code>OutputStream</code>.  It does this by calling the three parameter
115     * version of this method - <code>write(byte[], int, int)</code> in this
116     * class instead of writing to the underlying <code>OutputStream</code>
117     * directly.  This allows most subclasses to avoid overriding this method.
118     *
119     * @param buf The byte array to write bytes from
120     *
121     * @exception IOException If an error occurs
122     */
123   public void write(byte[] buf) //throws IOException
124   {
125     // Don't do checking here, per Java Lang Spec.
126     write(buf, 0, buf.length);
127   }
128
129   /**
130     * This method calls the <code>write(int)</code> method <code>len</code>
131     * times for all bytes from the array <code>buf</code> starting at index
132     * <code>offset</code>. Subclasses should overwrite this method to get a
133     * more efficient implementation.
134     *
135     * @param buf The byte array to write bytes from
136     * @param offset The index into the array to start writing bytes from
137     * @param len The number of bytes to write
138     *
139     * @exception IOException If an error occurs
140     */
141   public void write(byte[] buf, int offset, int len) //throws IOException
142   {
143     // Don't do checking here, per Java Lang Spec.
144     for (int i=0; i < len; i++) 
145       write(buf[offset + i]);
146
147   }
148
149 } // class FilterOutputStream
150