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.FilterInputStream;
46 import java.io.IOException;
47 import java.io.InputStream;
48
49 /**
50 * Class PersistentInputStream implements an input stream for which close() can
51 * be disabled.
52 *
53 */
54 public class PersistentInputStream extends FilterInputStream {
55 boolean iClosable = false;
56
57 boolean iClosed = false;
58
59 /**
60 * Ctor.
61 *
62 * @param pStream
63 * The underlying stream
64 */
65 public PersistentInputStream(InputStream pStream) {
66 this(pStream, false);
67 }
68
69 /**
70 * Ctor.
71 *
72 * @param pStream
73 * The underlying stream
74 * @param pClosable
75 * If <code>false</code> this stream will ignore calls to the
76 * close() method.
77 */
78 public PersistentInputStream(InputStream pStream, boolean pClosable) {
79 super(pStream);
80 this.iClosable = pClosable;
81 }
82
83 @Override
84 public synchronized void close() throws IOException {
85 if (!this.iClosed) {
86 this.iClosed = true;
87 if (this.iClosable) this.in.close();
88 } else throw new IOException("Error while closing the input stream. It was already closed");
89 }
90 }