Home | History | Annotate | Download | only in output
      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.FilterOutputStream;
     20 import java.io.IOException;
     21 import java.io.OutputStream;
     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 FilterOutputStream
     27  * to increase reusability.
     28  *
     29  * @author Stephen Colebourne
     30  * @version $Id: ProxyOutputStream.java 610010 2008-01-08 14:50:59Z niallp $
     31  */
     32 public class ProxyOutputStream extends FilterOutputStream {
     33 
     34     /**
     35      * Constructs a new ProxyOutputStream.
     36      *
     37      * @param proxy  the OutputStream to delegate to
     38      */
     39     public ProxyOutputStream(OutputStream proxy) {
     40         super(proxy);
     41         // the proxy is stored in a protected superclass variable named 'out'
     42     }
     43 
     44     /**
     45      * Invokes the delegate's <code>write(int)</code> method.
     46      * @param idx the byte to write
     47      * @throws IOException if an I/O error occurs
     48      */
     49     public void write(int idx) throws IOException {
     50         out.write(idx);
     51     }
     52 
     53     /**
     54      * Invokes the delegate's <code>write(byte[])</code> method.
     55      * @param bts the bytes to write
     56      * @throws IOException if an I/O error occurs
     57      */
     58     public void write(byte[] bts) throws IOException {
     59         out.write(bts);
     60     }
     61 
     62     /**
     63      * Invokes the delegate's <code>write(byte[])</code> method.
     64      * @param bts the bytes to write
     65      * @param st The start offset
     66      * @param end The number of bytes to write
     67      * @throws IOException if an I/O error occurs
     68      */
     69     public void write(byte[] bts, int st, int end) throws IOException {
     70         out.write(bts, st, end);
     71     }
     72 
     73     /**
     74      * Invokes the delegate's <code>flush()</code> method.
     75      * @throws IOException if an I/O error occurs
     76      */
     77     public void flush() throws IOException {
     78         out.flush();
     79     }
     80 
     81     /**
     82      * Invokes the delegate's <code>close()</code> method.
     83      * @throws IOException if an I/O error occurs
     84      */
     85     public void close() throws IOException {
     86         out.close();
     87     }
     88 
     89 }
     90