01: /*
02:
03: Derby - Class org.apache.derby.client.am.AsciiStream
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to You under the Apache License, Version 2.0
09: (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: package org.apache.derby.client.am;
22:
23: import java.io.StringReader;
24:
25: public class AsciiStream extends java.io.InputStream {
26: private java.io.Reader reader_;
27: private String materializedString_;
28: private int charsRead_ = 0;
29:
30: public AsciiStream(String materializedString) {
31: this (materializedString, new StringReader(materializedString));
32: }
33:
34: public AsciiStream(String materializedString, java.io.Reader reader) {
35: reader_ = reader;
36: materializedString_ = materializedString;
37: }
38:
39: public int read() throws java.io.IOException {
40: int oneChar = reader_.read();
41: ++charsRead_;
42: if (oneChar != -1) // if not eos
43: {
44: if (oneChar <= 0x00ff)
45: return oneChar;
46: else
47: return 0x003f;
48:
49: } else {
50: return -1; // end of stream
51: }
52: }
53:
54: public int available() {
55: return materializedString_.length() - charsRead_;
56: }
57: }
|