001 /* FilterWriter.java -- Parent class for output streams that filter
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 * Status: Complete to version 1.1.
044 */
045
046 /**
047 * This class is the common superclass of output character stream classes
048 * that filter the output they write. These classes typically transform the
049 * data in some way prior to writing it out to another underlying
050 * <code>Writer</code>. This class simply overrides all the
051 * methods in <code>Writer</code> to redirect them to the
052 * underlying stream. Subclasses provide actual filtering.
053 *
054 * @author Aaron M. Renn (arenn@urbanophile.com)
055 * @author Tom Tromey (tromey@cygnus.com)
056 */
057 public abstract class FilterWriter extends Writer
058 {
059 /**
060 * This is the subordinate <code>Writer</code> that this class
061 * redirects its method calls to.
062 */
063 protected Writer out;
064
065 /**
066 * This method initializes an instance of <code>FilterWriter</code>
067 * to write to the specified subordinate <code>Writer</code>.
068 * The given <code>Writer</code> will be used as <code>lock</code> for
069 * the newly created <code>FilterWriter</code>.
070 *
071 * @param out The <code>Writer</code> to write to
072 */
073 protected FilterWriter(Writer out)
074 {
075 super(out.lock);
076 this.out = out;
077 }
078
079 /**
080 * This method closes the underlying <code>Writer</code>. Any
081 * further attempts to write to this stream may throw an exception.
082 *
083 * @exception IOException If an error occurs
084 */
085 public void close() throws IOException
086 {
087 out.close();
088 }
089
090 /**
091 * This method attempt to flush all buffered output to be written to the
092 * underlying output sink.
093 *
094 * @exception IOException If an error occurs
095 */
096 public void flush() throws IOException
097 {
098 out.flush();
099 }
100
101 /**
102 * This method writes a single char of output to the underlying
103 * <code>Writer</code>.
104 *
105 * @param b The char to write, passed as an int.
106 *
107 * @exception IOException If an error occurs
108 */
109 public void write(int b) throws IOException
110 {
111 out.write(b);
112 }
113
114 /**
115 * This method writes <code>len</code> chars from the array <code>buf</code>
116 * starting at index <code>offset</code> to the underlying
117 * <code>Writer</code>.
118 *
119 * @param buf The char array to write chars from
120 * @param offset The index into the array to start writing chars from
121 * @param len The number of chars to write
122 *
123 * @exception IOException If an error occurs
124 */
125 public void write(char[] buf, int offset, int len) throws IOException
126 {
127 out.write(buf, offset, len);
128 }
129
130 /**
131 * This method writes <code>len</code> chars from the <code>String</code>
132 * starting at position <code>offset</code>.
133 *
134 * @param str The <code>String</code> that is to be written
135 * @param offset The character offset into the <code>String</code>
136 * to start writing from
137 * @param len The number of chars to write
138 *
139 * @exception IOException If an error occurs
140 */
141 public void write(String str, int offset, int len) throws IOException
142 {
143 out.write(str, offset, len);
144 }
145
146 } // class FilterWriter