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.FilterOutputStream;
020 import java.io.IOException;
021 import java.io.OutputStream;
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 FilterOutputStream
027 * to increase reusability.
028 *
029 * @author Stephen Colebourne
030 * @version $Id: ProxyOutputStream.java 610010 2008-01-08 14:50:59Z niallp $
031 */
032 public class ProxyOutputStream extends FilterOutputStream {
033
034 /**
035 * Constructs a new ProxyOutputStream.
036 *
037 * @param proxy the OutputStream to delegate to
038 */
039 public ProxyOutputStream(OutputStream proxy) {
040 super(proxy);
041 // the proxy is stored in a protected superclass variable named 'out'
042 }
043
044 /**
045 * Invokes the delegate's <code>write(int)</code> method.
046 * @param idx the byte to write
047 * @throws IOException if an I/O error occurs
048 */
049 public void write(int idx) throws IOException {
050 out.write(idx);
051 }
052
053 /**
054 * Invokes the delegate's <code>write(byte[])</code> method.
055 * @param bts the bytes to write
056 * @throws IOException if an I/O error occurs
057 */
058 public void write(byte[] bts) throws IOException {
059 out.write(bts);
060 }
061
062 /**
063 * Invokes the delegate's <code>write(byte[])</code> method.
064 * @param bts the bytes to write
065 * @param st The start offset
066 * @param end The number of bytes to write
067 * @throws IOException if an I/O error occurs
068 */
069 public void write(byte[] bts, int st, int end) throws IOException {
070 out.write(bts, st, end);
071 }
072
073 /**
074 * Invokes the delegate's <code>flush()</code> method.
075 * @throws IOException if an I/O error occurs
076 */
077 public void flush() throws IOException {
078 out.flush();
079 }
080
081 /**
082 * Invokes the delegate's <code>close()</code> method.
083 * @throws IOException if an I/O error occurs
084 */
085 public void close() throws IOException {
086 out.close();
087 }
088
089 }