KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > client > am > CloseFilterInputStream


1 /*
2
3    Derby - Class org.apache.derby.client.am.CloseFilterInputStream
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20 */

21
22 package org.apache.derby.client.am;
23
24 import java.io.InputStream JavaDoc;
25 import java.io.FilterInputStream JavaDoc;
26
27 import java.io.IOException JavaDoc;
28 import org.apache.derby.shared.common.i18n.MessageUtil;
29 import org.apache.derby.shared.common.reference.MessageId;
30
31 class CloseFilterInputStream extends FilterInputStream JavaDoc {
32     
33     private static final String JavaDoc ALREADY_CLOSED_ERR_MESSAGE =
34             SqlException.getMessageUtil().getTextMessage(
35                 MessageId.CONN_ALREADY_CLOSED);
36     
37     private boolean closed;
38     
39     public CloseFilterInputStream(InputStream JavaDoc is){
40         
41         super(is);
42         closed = false;
43         
44     }
45     
46     
47     public int read()
48         throws IOException JavaDoc {
49
50         if(closed){
51             throw new IOException JavaDoc(ALREADY_CLOSED_ERR_MESSAGE);
52         }
53         
54         return super.read();
55         
56     }
57     
58
59     public int read(byte[] b)
60         throws IOException JavaDoc {
61         
62         if(closed){
63             throw new IOException JavaDoc(ALREADY_CLOSED_ERR_MESSAGE);
64         }
65
66         return super.read(b);
67
68     }
69     
70     
71     public int read(byte[] b,
72             int off,
73             int len)
74         throws IOException JavaDoc{
75         
76         if(closed){
77             throw new IOException JavaDoc(ALREADY_CLOSED_ERR_MESSAGE);
78         }
79
80         return super.read(b, off, len);
81
82     }
83
84     
85     public long skip(long n)
86         throws IOException JavaDoc{
87
88         if(closed){
89             throw new IOException JavaDoc(ALREADY_CLOSED_ERR_MESSAGE);
90         }
91         
92         return super.skip(n);
93         
94     }
95     
96     
97     public int available()
98         throws IOException JavaDoc{
99         
100         if(closed){
101             throw new IOException JavaDoc(ALREADY_CLOSED_ERR_MESSAGE);
102         }
103
104         return super.available();
105         
106     }
107     
108     
109     public void close()
110         throws IOException JavaDoc{
111         
112         super.close();
113         closed = true;
114         
115     }
116     
117     
118 }
119
Popular Tags