KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.client.am.AsciiStream
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 package org.apache.derby.client.am;
22
23 import java.io.StringReader JavaDoc;
24
25 public class AsciiStream extends java.io.InputStream JavaDoc {
26     private java.io.Reader JavaDoc reader_;
27     private String JavaDoc materializedString_;
28     private int charsRead_ = 0;
29     
30     public AsciiStream(String JavaDoc materializedString){
31         this(materializedString,new StringReader JavaDoc(materializedString));
32     }
33     
34     public AsciiStream(String JavaDoc materializedString, java.io.Reader JavaDoc reader) {
35         reader_ = reader;
36         materializedString_ = materializedString;
37     }
38
39     public int read() throws java.io.IOException JavaDoc {
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 }
58
Popular Tags