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. */
40 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
41 * "The Java Language Specification", ISBN 0-201-63451-1
42 * Status: Complete to version 1.1.
46 * This class is the common superclass of output stream classes that filter the
47 * output they write. These classes typically transform the data in some way
48 * prior to writing it out to another underlying <code>OutputStream</code>. This
49 * class simply overrides all the methods in <code>OutputStream</code> to
50 * redirect them to the underlying stream. Subclasses provide actual filtering.
52 * @author Aaron M. Renn (arenn@urbanophile.com)
53 * @author Tom Tromey (tromey@cygnus.com)
55 public class FilterOutputStream extends OutputStream {
57 * This is the subordinate <code>OutputStream</code> that this class redirects
58 * its method calls to.
60 protected OutputStream out;
63 * This method initializes an instance of <code>FilterOutputStream</code> to
64 * write to the specified subordinate <code>OutputStream</code>.
67 * The <code>OutputStream</code> to write to
69 public FilterOutputStream(OutputStream out) {
74 * This method closes the underlying <code>OutputStream</code>. Any further
75 * attempts to write to this stream may throw an exception.
77 * @exception IOException
80 public void close() // throws IOException
87 * This method attempt to flush all buffered output to be written to the
88 * underlying output sink.
90 * @exception IOException
93 public void flush() // throws IOException
99 * This method writes a single byte of output to the underlying
100 * <code>OutputStream</code>.
103 * The byte to write, passed as an int.
105 * @exception IOException
108 public void write(int b) // throws IOException
114 * This method writes all the bytes in the specified array to the underlying
115 * <code>OutputStream</code>. It does this by calling the three parameter
116 * version of this method - <code>write(byte[], int, int)</code> in this class
117 * instead of writing to the underlying <code>OutputStream</code> directly.
118 * This allows most subclasses to avoid overriding this method.
121 * The byte array to write bytes from
123 * @exception IOException
126 public void write(byte[] buf) // throws IOException
128 // Don't do checking here, per Java Lang Spec.
129 write(buf, 0, buf.length);
133 * This method calls the <code>write(int)</code> method <code>len</code> times
134 * for all bytes from the array <code>buf</code> starting at index
135 * <code>offset</code>. Subclasses should overwrite this method to get a more
136 * efficient implementation.
139 * The byte array to write bytes from
141 * The index into the array to start writing bytes from
143 * The number of bytes to write
145 * @exception IOException
148 public void write(byte[] buf, int offset, int len) // throws IOException
150 // Don't do checking here, per Java Lang Spec.
151 for (int i = 0; i < len; i++)
152 write(buf[offset + i]);
156 } // class FilterOutputStream