Source for java.io.FilterWriter

   1: /* FilterWriter.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 character stream classes
  48:   * that 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>Writer</code>.  This class simply overrides all the
  51:   * methods in <code>Writer</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 abstract class FilterWriter extends Writer
  58: {
  59:   /**
  60:     * This is the subordinate <code>Writer</code> that this class
  61:     * redirects its method calls to.
  62:     */
  63:   protected Writer out;
  64: 
  65:   /**
  66:     * This method initializes an instance of <code>FilterWriter</code>
  67:     * to write to the specified subordinate <code>Writer</code>.
  68:     * The given <code>Writer</code> will be used as <code>lock</code> for
  69:     * the newly created <code>FilterWriter</code>.
  70:     *
  71:     * @param out The <code>Writer</code> to write to
  72:     */
  73:   protected FilterWriter(Writer out)
  74:   {
  75:     super(out.lock);
  76:     this.out = out;
  77:   }
  78: 
  79:   /**
  80:     * This method closes the underlying <code>Writer</code>.  Any
  81:     * further attempts to write to this stream may throw an exception.
  82:     *
  83:     * @exception IOException If an error occurs
  84:     */
  85:   public void close() throws IOException
  86:   {
  87:     out.close();
  88:   }
  89: 
  90:   /**
  91:     * This method attempt to flush all buffered output to be written to the
  92:     * underlying output sink.
  93:     *
  94:     * @exception IOException If an error occurs
  95:     */
  96:   public void flush() throws IOException
  97:   {
  98:     out.flush();
  99:   }
 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