1 /* 2 * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.io; 27 28 29 /** 30 * Abstract class for writing filtered character streams. 31 * The abstract class <code>FilterWriter</code> itself 32 * provides default methods that pass all requests to the 33 * contained stream. Subclasses of <code>FilterWriter</code> 34 * should override some of these methods and may also 35 * provide additional methods and fields. 36 * 37 * @author Mark Reinhold 38 * @since 1.1 39 */ 40 41 public abstract class FilterWriter extends Writer { 42 43 /** 44 * The underlying character-output stream. 45 */ 46 protected Writer out; 47 48 /** 49 * Create a new filtered writer. 50 * 51 * @param out a Writer object to provide the underlying stream. 52 * @throws NullPointerException if <code>out</code> is <code>null</code> 53 */ 54 protected FilterWriter(Writer out) { 55 super(out); 56 this.out = out; 57 } 58 59 /** 60 * Writes a single character. 61 * 62 * @exception IOException If an I/O error occurs 63 */ 64 public void write(int c) throws IOException { 65 out.write(c); 66 } 67 68 /** 69 * Writes a portion of an array of characters. 70 * 71 * @param cbuf Buffer of characters to be written 72 * @param off Offset from which to start reading characters 73 * @param len Number of characters to be written 74 * 75 * @throws IndexOutOfBoundsException 76 * If the values of the {@code off} and {@code len} parameters 77 * cause the corresponding method of the underlying {@code Writer} 78 * to throw an {@code IndexOutOfBoundsException} 79 * 80 * @throws IOException If an I/O error occurs 81 */ 82 public void write(char[] cbuf, int off, int len) throws IOException { 83 out.write(cbuf, off, len); 84 } 85 86 /** 87 * Writes a portion of a string. 88 * 89 * @param str String to be written 90 * @param off Offset from which to start reading characters 91 * @param len Number of characters to be written 92 * 93 * @throws IndexOutOfBoundsException 94 * If the values of the {@code off} and {@code len} parameters 95 * cause the corresponding method of the underlying {@code Writer} 96 * to throw an {@code IndexOutOfBoundsException} 97 * 98 * @throws IOException If an I/O error occurs 99 */ 100 public void write(String str, int off, int len) throws IOException { 101 out.write(str, off, len); 102 } 103 104 /** 105 * Flushes the stream. 106 * 107 * @exception IOException If an I/O error occurs 108 */ 109 public void flush() throws IOException { 110 out.flush(); 111 } 112 113 public void close() throws IOException { 114 out.close(); 115 } 116 117 }