Source Code Cross Referenced for DataInputStream.java in  » Database-DBMS » Quadcap-Embeddable-Database » com » quadcap » sql » io » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » Quadcap Embeddable Database » com.quadcap.sql.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.quadcap.sql.io;
002:
003:        /* Copyright 1999 - 2003 Quadcap Software.  All rights reserved.
004:         *
005:         * This software is distributed under the Quadcap Free Software License.
006:         * This software may be used or modified for any purpose, personal or
007:         * commercial.  Open Source redistributions are permitted.  Commercial
008:         * redistribution of larger works derived from, or works which bundle
009:         * this software requires a "Commercial Redistribution License"; see
010:         * http://www.quadcap.com/purchase.
011:         *
012:         * Redistributions qualify as "Open Source" under  one of the following terms:
013:         *   
014:         *    Redistributions are made at no charge beyond the reasonable cost of
015:         *    materials and delivery.
016:         *
017:         *    Redistributions are accompanied by a copy of the Source Code or by an
018:         *    irrevocable offer to provide a copy of the Source Code for up to three
019:         *    years at the cost of materials and delivery.  Such redistributions
020:         *    must allow further use, modification, and redistribution of the Source
021:         *    Code under substantially the same terms as this license.
022:         *
023:         * Redistributions of source code must retain the copyright notices as they
024:         * appear in each source code file, these license terms, and the
025:         * disclaimer/limitation of liability set forth as paragraph 6 below.
026:         *
027:         * Redistributions in binary form must reproduce this Copyright Notice,
028:         * these license terms, and the disclaimer/limitation of liability set
029:         * forth as paragraph 6 below, in the documentation and/or other materials
030:         * provided with the distribution.
031:         *
032:         * The Software is provided on an "AS IS" basis.  No warranty is
033:         * provided that the Software is free of defects, or fit for a
034:         * particular purpose.  
035:         *
036:         * Limitation of Liability. Quadcap Software shall not be liable
037:         * for any damages suffered by the Licensee or any third party resulting
038:         * from use of the Software.
039:         */
040:
041:        import java.io.BufferedReader;
042:        import java.io.DataInput;
043:        import java.io.EOFException;
044:        import java.io.InputStream;
045:        import java.io.IOException;
046:
047:        import com.quadcap.io.InputStreamReader;
048:
049:        import com.quadcap.util.Debug;
050:        import com.quadcap.util.Util;
051:
052:        /**
053:         * Implement low level serialization
054:         */
055:        public class DataInputStream extends InputStream implements  DataInput {
056:            InputStream in;
057:            static final boolean buffered = false;
058:
059:            static final int MAX = 4096;
060:            byte[] buf = new byte[MAX];
061:            int pos;
062:            int len;
063:
064:            public DataInputStream(InputStream in) {
065:                this .in = in;
066:                this .pos = 0;
067:                this .len = 0;
068:            }
069:
070:            long position;
071:
072:            public void setPosition(long p) {
073:                this .position = p;
074:            }
075:
076:            public long getPosition() {
077:                return position;
078:            }
079:
080:            public void setInputStream(InputStream in) {
081:                this .in = in;
082:            }
083:
084:            public InputStream getInputStream() {
085:                return in;
086:            }
087:
088:            public void readFully(byte[] b) throws IOException {
089:                read(b, 0, b.length);
090:            }
091:
092:            public void readFully(byte[] b, int off, int len)
093:                    throws IOException {
094:                read(b, off, len);
095:            }
096:
097:            public int skipBytes(int n) throws IOException {
098:                return (int) skip(n);
099:            }
100:
101:            public boolean readBoolean() throws IOException {
102:                return read() == 1;
103:            }
104:
105:            public byte readByte() throws IOException {
106:                return (byte) read();
107:            }
108:
109:            public int readUnsignedByte() throws IOException {
110:                return read();
111:            }
112:
113:            public char readChar() throws IOException {
114:                return (char) readUnsignedShort();
115:            }
116:
117:            final long readLongByte() throws IOException {
118:                return readUnsignedByte();
119:            }
120:
121:            //#ifdef SMALLDB
122:            public long readLong() throws IOException {
123:                long ret = 0;
124:                long b;
125:                int shift = 0;
126:                do {
127:                    b = read();
128:                    ret |= ((b & 0x7f) << shift);
129:                    shift += 7;
130:                } while ((b & 0x80) != 0);
131:                return ret;
132:            }
133:
134:            public int readInt() throws IOException {
135:                int ret = 0;
136:                int b;
137:                int shift = 0;
138:                do {
139:                    b = read();
140:                    ret |= ((b & 0x7f) << shift);
141:                    shift += 7;
142:                } while ((b & 0x80) != 0);
143:                return ret;
144:            }
145:
146:            public short readShort() throws IOException {
147:                return (short) readInt();
148:            }
149:
150:            public int readUnsignedShort() throws IOException {
151:                return readInt();
152:            }
153:
154:            //#else
155:            //-    public short readShort() throws IOException {
156:            //-        return (short)readUnsignedShort();
157:            //-    }
158:            //-    
159:            //-    public int readUnsignedShort() throws IOException {
160:            //-        int ret = readUnsignedByte() << 8;
161:            //-        ret += readUnsignedByte();
162:            //-        return ret;
163:            //-    }
164:            //-    
165:            //-    public int readInt() throws IOException {
166:            //-        int ret = readUnsignedByte() << 24;
167:            //-        ret |= (readUnsignedByte() << 16);
168:            //-        ret |= (readUnsignedByte() << 8);
169:            //-        ret |= readUnsignedByte();
170:            //-        return ret;
171:            //-    }
172:            //-
173:            //-    public long readLong() throws IOException {
174:            //-        long ret = readLongByte() << 56;
175:            //-        ret |= (readLongByte() << 48);
176:            //-        ret |= (readLongByte() << 40);
177:            //-        ret |= (readLongByte() << 32);
178:            //-        ret |= (readLongByte() << 24);
179:            //-        ret |= (readLongByte() << 16);
180:            //-        ret |= (readLongByte() << 8);
181:            //-        ret |= readLongByte();
182:            //-        return ret;
183:            //-    }
184:            //#endif
185:
186:            public float readFloat() throws IOException {
187:                return Float.intBitsToFloat(readInt());
188:            }
189:
190:            public double readDouble() throws IOException {
191:                return Double.longBitsToDouble(readLong());
192:            }
193:
194:            public String readLine() throws IOException {
195:                InputStreamReader ns = new InputStreamReader(this );
196:                BufferedReader r = new BufferedReader(ns);
197:                return r.readLine();
198:            }
199:
200:            public String readUTF() throws IOException {
201:                throw new IOException("readUTF not implemented");
202:            }
203:
204:            final boolean fillBuffer() throws IOException {
205:                boolean ret = pos >= len;
206:                if (ret) {
207:                    len = in.read(buf, 0, buf.length);
208:                    pos = 0;
209:                    ret = pos >= len;
210:                }
211:                return ret;
212:            }
213:
214:            public int read() throws IOException {
215:                int ret = -1;
216:                if (buffered) {
217:                    if (!fillBuffer()) {
218:                        ret = buf[pos++] & 0xff;
219:                        position++;
220:                    }
221:                } else {
222:                    ret = in.read();
223:                    if (ret < 0) {
224:                        throw new EOFException();
225:                    }
226:                    position++;
227:                }
228:                //#ifdef DEBUG
229:                if (trace)
230:                    Debug.println("DIS.read() = " + ret);
231:                //#endif
232:                return ret;
233:            }
234:
235:            public int read(byte[] b, int off, int cnt) throws IOException {
236:                int ret = 0;
237:                //#ifdef DEBUG
238:                int xoff = off;
239:                int xcnt = cnt;
240:                //#endif
241:                if (buffered) {
242:                    while (cnt > 0 && !fillBuffer()) {
243:                        int amt = len - pos;
244:                        if (amt > cnt)
245:                            amt = cnt;
246:                        System.arraycopy(buf, pos, b, off, amt);
247:                        cnt -= amt;
248:                        off += amt;
249:                        ret += amt;
250:                        pos += amt;
251:                        position += amt;
252:                    }
253:                } else {
254:                    while (cnt > 0) {
255:                        int amt = in.read(b, off, cnt);
256:                        ret += amt;
257:                        position += amt;
258:                        off += amt;
259:                        cnt -= amt;
260:                    }
261:                }
262:                //#ifdef DEBUG
263:                if (trace) {
264:                    Debug.println("DIS.read() = " + ret + ": "
265:                            + Util.hexBytes(b, xoff, ret));
266:                }
267:                //#endif
268:                return ret;
269:            }
270:
271:            //#ifdef DEBUG
272:            static final boolean trace = false;
273:
274:            //#endif
275:
276:            public int read(byte[] buf) throws IOException {
277:                return read(buf, 0, buf.length);
278:            }
279:
280:            public long skip(long n) throws IOException {
281:                long ret = 0;
282:                if (buffered) {
283:                    while (n > 0 && !fillBuffer()) {
284:                        long amt = len - pos;
285:                        if (amt > n)
286:                            amt = n;
287:                        n -= amt;
288:                        pos += amt;
289:                        position += amt;
290:                    }
291:                } else {
292:                    ret = in.skip(n);
293:                }
294:                return ret;
295:            }
296:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.