1bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook/*
2bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Licensed to the Apache Software Foundation (ASF) under one or more
3bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * contributor license agreements.  See the NOTICE file distributed with
4bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * this work for additional information regarding copyright ownership.
5bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * The ASF licenses this file to You under the Apache License, Version 2.0
6bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * (the "License"); you may not use this file except in compliance with
7bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * the License.  You may obtain a copy of the License at
8bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook *
9bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook *      http://www.apache.org/licenses/LICENSE-2.0
10bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook *
11bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Unless required by applicable law or agreed to in writing, software
12bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * distributed under the License is distributed on an "AS IS" BASIS,
13bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * See the License for the specific language governing permissions and
15bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * limitations under the License.
16bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook */
17bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookpackage org.apache.commons.io.output;
18bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
19bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookimport java.io.OutputStream;
20bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
21bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook/**
22bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Proxy stream that prevents the underlying output stream from being closed.
23bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * <p>
24bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * This class is typically used in cases where an output stream needs to be
25bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * passed to a component that wants to explicitly close the stream even if
26bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * other components would still use the stream for output.
27bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook *
28bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @version $Id: CloseShieldOutputStream.java 587913 2007-10-24 15:47:30Z niallp $
29bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @since Commons IO 1.4
30bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook */
31bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookpublic class CloseShieldOutputStream extends ProxyOutputStream {
32bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
33bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
34bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Creates a proxy that shields the given output stream from being
35bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * closed.
36bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     *
37bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @param out underlying output stream
38bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
39bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public CloseShieldOutputStream(OutputStream out) {
40bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        super(out);
41bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
42bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
43bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
44bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Replaces the underlying output stream with a {@link ClosedOutputStream}
45bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * sentinel. The original output stream will remain open, but this proxy
46bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * will appear closed.
47bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
48bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public void close() {
49bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        out = new ClosedOutputStream();
50bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
51bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
52bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook}
53