0e1e9e94418ddf9e6e9751505e104058234ef062
[so/libs.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * ============LICENSE_END=========================================================
15  */
16
17 package com.woorea.openstack.connector;
18
19 import java.io.FilterInputStream;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.net.SocketException;
23
24 import org.jboss.resteasy.client.ClientExecutor;
25
26
27 public class RESTEasyInputStream extends FilterInputStream {
28
29     protected ClientExecutor clientExecutor;
30
31     public RESTEasyInputStream(InputStream inputStream, ClientExecutor clientExecutor) {
32         super(inputStream);
33         this.clientExecutor = clientExecutor;
34     }
35
36     @Override
37     public void close() throws IOException {
38         try {
39             clientExecutor.close();
40         } catch (Exception e) {
41             // Silently skip errors in the socket close errors
42         }
43
44         try {
45             super.close();
46         } catch (SocketException e) {
47             // We expect this exception because the socket is closed
48         } catch (IllegalStateException e) {
49             // We expect this exception because the socket is closed (httpclient 4.2)
50         }
51     }
52
53 }