1 /* FilterOutputStream.java -- Parent class for output streams that filter
2 Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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)
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.
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
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
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. */
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.
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.
54 * @author Aaron M. Renn (arenn@urbanophile.com)
55 * @author Tom Tromey (tromey@cygnus.com)
57 public class FilterOutputStream extends OutputStream
60 * This is the subordinate <code>OutputStream</code> that this class
61 * redirects its method calls to.
63 protected OutputStream out;
66 * This method initializes an instance of <code>FilterOutputStream</code>
67 * to write to the specified subordinate <code>OutputStream</code>.
69 * @param out The <code>OutputStream</code> to write to
71 public FilterOutputStream(OutputStream out)
77 * This method closes the underlying <code>OutputStream</code>. Any
78 * further attempts to write to this stream may throw an exception.
80 * @exception IOException If an error occurs
82 public void close() //throws IOException
89 * This method attempt to flush all buffered output to be written to the
90 * underlying output sink.
92 * @exception IOException If an error occurs
94 public void flush() //throws IOException
100 * This method writes a single byte of output to the underlying
101 * <code>OutputStream</code>.
103 * @param b The byte to write, passed as an int.
105 * @exception IOException If an error occurs
107 public void write(int b) //throws IOException
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.
119 * @param buf The byte array to write bytes from
121 * @exception IOException If an error occurs
123 public void write(byte[] buf) //throws IOException
125 // Don't do checking here, per Java Lang Spec.
126 write(buf, 0, buf.length);
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.
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
139 * @exception IOException If an error occurs
141 public void write(byte[] buf, int offset, int len) //throws IOException
143 // Don't do checking here, per Java Lang Spec.
144 for (int i=0; i < len; i++)
145 write(buf[offset + i]);
149 } // class FilterOutputStream