001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     * 
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.commons.io.output;
018    
019    import java.io.FilterWriter;
020    import java.io.IOException;
021    import java.io.Writer;
022    
023    /**
024     * A Proxy stream which acts as expected, that is it passes the method 
025     * calls on to the proxied stream and doesn't change which methods are 
026     * being called. It is an alternative base class to FilterWriter
027     * to increase reusability, because FilterWriter changes the 
028     * methods being called, such as write(char[]) to write(char[], int, int)
029     * and write(String) to write(String, int, int).
030     * 
031     * @author Stephen Colebourne
032     * @version $Id: ProxyWriter.java 610010 2008-01-08 14:50:59Z niallp $
033     */
034    public class ProxyWriter extends FilterWriter {
035    
036        /**
037         * Constructs a new ProxyWriter.
038         * 
039         * @param proxy  the Writer to delegate to
040         */
041        public ProxyWriter(Writer proxy) {
042            super(proxy);
043            // the proxy is stored in a protected superclass variable named 'out'
044        }
045    
046        /**
047         * Invokes the delegate's <code>write(int)</code> method.
048         * @param idx the character to write
049         * @throws IOException if an I/O error occurs
050         */
051        public void write(int idx) throws IOException {
052            out.write(idx);
053        }
054    
055        /**
056         * Invokes the delegate's <code>write(char[])</code> method.
057         * @param chr the characters to write
058         * @throws IOException if an I/O error occurs
059         */
060        public void write(char[] chr) throws IOException {
061            out.write(chr);
062        }
063    
064        /**
065         * Invokes the delegate's <code>write(char[], int, int)</code> method.
066         * @param chr the characters to write
067         * @param st The start offset
068         * @param end The number of characters to write
069         * @throws IOException if an I/O error occurs
070         */
071        public void write(char[] chr, int st, int end) throws IOException {
072            out.write(chr, st, end);
073        }
074    
075        /**
076         * Invokes the delegate's <code>write(String)</code> method.
077         * @param str the string to write
078         * @throws IOException if an I/O error occurs
079         */
080        public void write(String str) throws IOException {
081            out.write(str);
082        }
083    
084        /**
085         * Invokes the delegate's <code>write(String)</code> method.
086         * @param str the string to write
087         * @param st The start offset
088         * @param end The number of characters to write
089         * @throws IOException if an I/O error occurs
090         */
091        public void write(String str, int st, int end) throws IOException {
092            out.write(str, st, end);
093        }
094    
095        /**
096         * Invokes the delegate's <code>flush()</code> method.
097         * @throws IOException if an I/O error occurs
098         */
099        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    }