001: /*
002:
003: Derby - Class org.apache.derby.client.am.CloseFilterInputStream
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.client.am;
023:
024: import java.io.InputStream;
025: import java.io.FilterInputStream;
026:
027: import java.io.IOException;
028: import org.apache.derby.shared.common.i18n.MessageUtil;
029: import org.apache.derby.shared.common.reference.MessageId;
030:
031: class CloseFilterInputStream extends FilterInputStream {
032:
033: private static final String ALREADY_CLOSED_ERR_MESSAGE = SqlException
034: .getMessageUtil().getTextMessage(
035: MessageId.CONN_ALREADY_CLOSED);
036:
037: private boolean closed;
038:
039: public CloseFilterInputStream(InputStream is) {
040:
041: super (is);
042: closed = false;
043:
044: }
045:
046: public int read() throws IOException {
047:
048: if (closed) {
049: throw new IOException(ALREADY_CLOSED_ERR_MESSAGE);
050: }
051:
052: return super .read();
053:
054: }
055:
056: public int read(byte[] b) throws IOException {
057:
058: if (closed) {
059: throw new IOException(ALREADY_CLOSED_ERR_MESSAGE);
060: }
061:
062: return super .read(b);
063:
064: }
065:
066: public int read(byte[] b, int off, int len) throws IOException {
067:
068: if (closed) {
069: throw new IOException(ALREADY_CLOSED_ERR_MESSAGE);
070: }
071:
072: return super .read(b, off, len);
073:
074: }
075:
076: public long skip(long n) throws IOException {
077:
078: if (closed) {
079: throw new IOException(ALREADY_CLOSED_ERR_MESSAGE);
080: }
081:
082: return super .skip(n);
083:
084: }
085:
086: public int available() throws IOException {
087:
088: if (closed) {
089: throw new IOException(ALREADY_CLOSED_ERR_MESSAGE);
090: }
091:
092: return super .available();
093:
094: }
095:
096: public void close() throws IOException {
097:
098: super .close();
099: closed = true;
100:
101: }
102:
103: }
|