KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > database > CellInputStream


1 /**
2  * com.mckoi.database.CellInputStream 22 Nov 2000
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * Version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License Version 2 for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * Version 2 along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Change Log:
21  *
22  *
23  */

24
25 package com.mckoi.database;
26
27 import java.io.*;
28
29 /**
30  * An implementation of CellInput that reads data from an underlying stream.
31  *
32  * @author Tobias Downer
33  */

34
35 final class CellInputStream implements CellInput {
36
37   /**
38    * The parent input stream.
39    */

40   private InputStream parent_stream;
41
42   /**
43    * The Constructor.
44    */

45   CellInputStream(InputStream parent_stream) {
46     setParentStream(parent_stream);
47   }
48
49   /**
50    * Sets the parent input stream for this stream. This allows us to
51    * recycle this object.
52    */

53   public void setParentStream(InputStream parent_stream) {
54     this.parent_stream = parent_stream;
55   }
56
57   public int read() throws IOException {
58     return parent_stream.read();
59   }
60
61   public int read(byte b[], int off, int len) throws IOException {
62     return parent_stream.read(b, off, len);
63   }
64
65   public long skip(long n) throws IOException {
66     return parent_stream.skip(n);
67   }
68
69   public int available() throws IOException {
70     return parent_stream.available();
71   }
72
73   public void mark(int readAheadLimit) throws IOException {
74     parent_stream.mark(readAheadLimit);
75   }
76
77   public void reset() throws IOException {
78     parent_stream.reset();
79   }
80
81   public void close() throws IOException {
82     parent_stream.close();
83   }
84
85
86   // ---------- Implemented from DataInput ----------
87

88   public void readFully(byte[] b) throws IOException {
89     read(b, 0, b.length);
90   }
91
92   public void readFully(byte b[], int off, int len) throws IOException {
93     read(b, off, len);
94   }
95
96   public int skipBytes(int n) throws IOException {
97     return (int) skip(n);
98   }
99
100   public boolean readBoolean() throws IOException {
101     return (read() != 0);
102   }
103
104   public byte readByte() throws IOException {
105     return (byte) read();
106   }
107
108   public int readUnsignedByte() throws IOException {
109     return read();
110   }
111
112   public short readShort() throws IOException {
113     int ch1 = read();
114     int ch2 = read();
115     return (short)((ch1 << 8) + (ch2 << 0));
116   }
117
118   public int readUnsignedShort() throws IOException {
119     int ch1 = read();
120     int ch2 = read();
121     return (ch1 << 8) + (ch2 << 0);
122   }
123
124   public char readChar() throws IOException {
125     int ch1 = read();
126     int ch2 = read();
127     return (char)((ch1 << 8) + (ch2 << 0));
128   }
129
130   private char[] char_buffer;
131
132   public String JavaDoc readChars(int length) throws IOException {
133     if (length <= 8192) {
134       if (char_buffer == null) {
135         char_buffer = new char[8192];
136       }
137       for (int i = 0; i < length; ++i) {
138         char_buffer[i] = readChar();
139       }
140       return new String JavaDoc(char_buffer, 0, length);
141     }
142     else {
143       StringBuffer JavaDoc chrs = new StringBuffer JavaDoc(length);
144       for (int i = length; i > 0; --i) {
145         chrs.append(readChar());
146       }
147       return new String JavaDoc(chrs);
148     }
149   }
150
151   public int readInt() throws IOException {
152     int ch1 = read();
153     int ch2 = read();
154     int ch3 = read();
155     int ch4 = read();
156     return (int)((ch1 << 24) + (ch2 << 16) +
157                  (ch3 << 8) + (ch4 << 0));
158   }
159
160   public long readLong() throws IOException {
161     return ((long)(readInt()) << 32) + (readInt() & 0xFFFFFFFFL);
162   }
163
164   public float readFloat() throws IOException {
165     return Float.intBitsToFloat(readInt());
166   }
167
168   public double readDouble() throws IOException {
169     return Double.longBitsToDouble(readLong());
170   }
171
172   public String JavaDoc readLine() throws IOException {
173     throw new Error JavaDoc("Not implemented.");
174   }
175
176   public String JavaDoc readUTF() throws IOException {
177     throw new Error JavaDoc("Not implemented.");
178   }
179
180 }
181
Popular Tags