14fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy/*
24fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Licensed to the Apache Software Foundation (ASF) under one or more
34fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * contributor license agreements.  See the NOTICE file distributed with
44fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * this work for additional information regarding copyright ownership.
54fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * The ASF licenses this file to You under the Apache License, Version 2.0
64fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * (the "License"); you may not use this file except in compliance with
74fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * the License.  You may obtain a copy of the License at
84fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy *
94fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy *      http://www.apache.org/licenses/LICENSE-2.0
104fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy *
114fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Unless required by applicable law or agreed to in writing, software
124fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * distributed under the License is distributed on an "AS IS" BASIS,
134fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
144fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * See the License for the specific language governing permissions and
154fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * limitations under the License.
164fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */
174fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedypackage org.apache.commons.io.output;
184fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
194fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedyimport java.io.IOException;
204fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedyimport java.io.OutputStream;
214fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
224fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy/**
234fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Closed output stream. This stream throws an exception on all attempts to
244fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * write something to the stream.
254fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * <p>
264fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Typically uses of this class include testing for corner cases in methods
274fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * that accept an output stream and acting as a sentinel value instead of
284fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * a <code>null</code> output stream.
294fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy *
304fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @version $Id: ClosedOutputStream.java 601751 2007-12-06 14:55:45Z niallp $
314fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @since Commons IO 1.4
324fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */
334fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedypublic class ClosedOutputStream extends OutputStream {
344fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
354fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
364fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * A singleton.
374fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
384fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public static final ClosedOutputStream CLOSED_OUTPUT_STREAM = new ClosedOutputStream();
394fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
404fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
414fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Throws an {@link IOException} to indicate that the stream is closed.
424fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     *
434fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param b ignored
444fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @throws IOException always thrown
454fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
464fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public void write(int b) throws IOException {
474fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        throw new IOException("write(" + b + ") failed: stream is closed");
484fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
494fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
504fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy}
51