1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.commons.io.output; 18 19 import java.io.FilterWriter; 20 import java.io.IOException; 21 import java.io.Writer; 22 23 /** 24 * A Proxy stream which acts as expected, that is it passes the method 25 * calls on to the proxied stream and doesn't change which methods are 26 * being called. It is an alternative base class to FilterWriter 27 * to increase reusability, because FilterWriter changes the 28 * methods being called, such as write(char[]) to write(char[], int, int) 29 * and write(String) to write(String, int, int). 30 * 31 * @author Stephen Colebourne 32 * @version $Id: ProxyWriter.java 610010 2008-01-08 14:50:59Z niallp $ 33 */ 34 public class ProxyWriter extends FilterWriter { 35 36 /** 37 * Constructs a new ProxyWriter. 38 * 39 * @param proxy the Writer to delegate to 40 */ 41 public ProxyWriter(Writer proxy) { 42 super(proxy); 43 // the proxy is stored in a protected superclass variable named 'out' 44 } 45 46 /** 47 * Invokes the delegate's <code>write(int)</code> method. 48 * @param idx the character to write 49 * @throws IOException if an I/O error occurs 50 */ 51 public void write(int idx) throws IOException { 52 out.write(idx); 53 } 54 55 /** 56 * Invokes the delegate's <code>write(char[])</code> method. 57 * @param chr the characters to write 58 * @throws IOException if an I/O error occurs 59 */ 60 public void write(char[] chr) throws IOException { 61 out.write(chr); 62 } 63 64 /** 65 * Invokes the delegate's <code>write(char[], int, int)</code> method. 66 * @param chr the characters to write 67 * @param st The start offset 68 * @param end The number of characters to write 69 * @throws IOException if an I/O error occurs 70 */ 71 public void write(char[] chr, int st, int end) throws IOException { 72 out.write(chr, st, end); 73 } 74 75 /** 76 * Invokes the delegate's <code>write(String)</code> method. 77 * @param str the string to write 78 * @throws IOException if an I/O error occurs 79 */ 80 public void write(String str) throws IOException { 81 out.write(str); 82 } 83 84 /** 85 * Invokes the delegate's <code>write(String)</code> method. 86 * @param str the string to write 87 * @param st The start offset 88 * @param end The number of characters to write 89 * @throws IOException if an I/O error occurs 90 */ 91 public void write(String str, int st, int end) throws IOException { 92 out.write(str, st, end); 93 } 94 95 /** 96 * Invokes the delegate's <code>flush()</code> method. 97 * @throws IOException if an I/O error occurs 98 */ 99 public void flush() throws IOException { 100 out.flush(); 101 } 102 103 /** 104 * Invokes the delegate's <code>close()</code> method. 105 * @throws IOException if an I/O error occurs 106 */ 107 public void close() throws IOException { 108 out.close(); 109 } 110 111 } 112