View Javadoc
1   /*
2     (C) Copyright IBM Corp. 2005, 2009
3   
4     THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
5     ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
6     CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
7   
8     You can obtain a current copy of the Eclipse Public License from
9     http://www.opensource.org/licenses/eclipse-1.0.php
10  
11    @author : Roberto Pineiro, IBM, roberto.pineiro@us.ibm.com
12   * @author : Chung-hao Tan, IBM, chungtan@us.ibm.com
13   * 
14   * 
15   * Change History
16   * Flag       Date        Prog         Description
17   *------------------------------------------------------------------------------- 
18   * 1535756    2006-08-07  lupusalex    Make code warning free
19   * 1565892    2006-11-28  lupusalex    Make SBLIM client JSR48 compliant
20   * 2003590    2008-06-30  blaschke-oss Change licensing from CPL to EPL
21   * 2524131    2009-01-21  raman_arora  Upgrade client to JDK 1.5 (Phase 1)
22   */
23  package org.metricshub.wbem.sblim.cimclient.internal.http.io;
24  
25  /*-
26   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
27   * WBEM Java Client
28   * ჻჻჻჻჻჻
29   * Copyright 2023 - 2025 MetricsHub
30   * ჻჻჻჻჻჻
31   * Licensed under the Apache License, Version 2.0 (the "License");
32   * you may not use this file except in compliance with the License.
33   * You may obtain a copy of the License at
34   *
35   *      http://www.apache.org/licenses/LICENSE-2.0
36   *
37   * Unless required by applicable law or agreed to in writing, software
38   * distributed under the License is distributed on an "AS IS" BASIS,
39   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40   * See the License for the specific language governing permissions and
41   * limitations under the License.
42   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
43   */
44  
45  import java.io.FilterOutputStream;
46  import java.io.IOException;
47  import java.io.OutputStream;
48  
49  /**
50   * Class PersistentOutputStream implements an output stream for which close()
51   * can be disabled.
52   */
53  public class PersistentOutputStream extends FilterOutputStream {
54  	boolean iClosable = false;
55  
56  	boolean iClosed = false;
57  
58  	/**
59  	 * Ctor.
60  	 *
61  	 * @param pStream
62  	 *            The underlying stream
63  	 */
64  	public PersistentOutputStream(OutputStream pStream) {
65  		this(pStream, false);
66  	}
67  
68  	/**
69  	 * Ctor.
70  	 *
71  	 * @param pStream
72  	 *            The underlying stream
73  	 * @param pClosable
74  	 *            If <code>false</code> this stream will ignore calls to the
75  	 *            close() method.
76  	 */
77  	public PersistentOutputStream(OutputStream pStream, boolean pClosable) {
78  		super(pStream);
79  		this.iClosable = pClosable;
80  	}
81  
82  	@Override
83  	public synchronized void close() throws IOException {
84  		if (!this.iClosed) {
85  			this.iClosed = true;
86  			if (this.iClosable) this.out.close();
87  		} else throw new IOException("Error while closing the Output stream. It was already closed");
88  	}
89  }