001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.internal;
014
015import java.io.*;
016
017/**
018 * Wraps an existing {@link OutputStream} where the {@link #close()} method is a no-op.
019 *
020 * <p>
021 * Useful in cases where you're working with streams that should not be implicitly closed.
022 *
023 * <h5 class='section'>See Also:</h5><ul>
024 * </ul>
025 */
026public final class NoCloseOutputStream extends OutputStream {
027
028   private final OutputStream os;
029
030   /**
031    * Constructor.
032    *
033    * @param os The output stream to wrap.
034    */
035   public NoCloseOutputStream(OutputStream os) {
036      this.os = os;
037   }
038
039   @Override /* OutputStream */
040   public void write(int b) throws IOException {
041      os.write(b);
042   }
043
044   @Override /* OutputStream */
045   public void write(byte[] b) throws IOException {
046      os.write(b);
047   }
048
049   @Override /* OutputStream */
050   public void write(byte[] b, int off, int len) throws IOException {
051      os.write(b, off, len);
052   }
053
054   @Override /* OutputStream */
055   public void flush() throws IOException {
056      os.flush();
057   }
058
059   @Override /* OutputStream */
060   public void close() throws IOException {
061      os.flush();
062   }
063}