Source Code Cross Referenced for EndianDataInputStream.java in  » GIS » openjump » com » vividsolutions » jump » 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 » GIS » openjump » com.vividsolutions.jump.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * EndianDataInputStream.java
003:         *
004:         * Created on September 6, 2002, 1:42 PM
005:         */
006:        /*
007:         * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI 
008:         * for visualizing and manipulating spatial features with geometry and attributes.
009:         *
010:         * Copyright (C) 2003 Vivid Solutions
011:         * 
012:         * This program is free software; you can redistribute it and/or
013:         * modify it under the terms of the GNU General Public License
014:         * as published by the Free Software Foundation; either version 2
015:         * of the License, or (at your option) any later version.
016:         * 
017:         * This program is distributed in the hope that it will be useful,
018:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
019:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
020:         * GNU General Public License for more details.
021:         * 
022:         * You should have received a copy of the GNU General Public License
023:         * along with this program; if not, write to the Free Software
024:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
025:         * 
026:         * For more information, contact:
027:         *
028:         * Vivid Solutions
029:         * Suite #1A
030:         * 2328 Government Street
031:         * Victoria BC  V8T 5G5
032:         * Canada
033:         *
034:         * (250)385-6040
035:         * www.vividsolutions.com
036:         */
037:
038:        package com.vividsolutions.jump.io;
039:
040:        import java.io.DataInputStream;
041:        import java.io.IOException;
042:        import java.io.BufferedInputStream;
043:
044:        /**
045:         *  A class that gives most of the functionality of DataInputStream, but is endian aware.
046:         *  Uses a real java.io.DataInputStream to actually do the writing.
047:         */
048:        public class EndianDataInputStream {
049:            private java.io.DataInputStream inputStream;
050:            private byte[] workSpace = new byte[8]; //chars are 16 bits, so we always quash the 1st 8 bits
051:
052:            /** Creates new EndianDataInputStream */
053:            public EndianDataInputStream(java.io.InputStream in) {
054:                inputStream = new DataInputStream(new BufferedInputStream(in));
055:            }
056:
057:            /** close the stream**/
058:            public void close() throws IOException {
059:                inputStream.close();
060:            }
061:
062:            /** read a byte in BigEndian - the same as LE because its only 1 byte*/
063:            public byte readByteBE() throws IOException {
064:                return inputStream.readByte();
065:            }
066:
067:            /** read a byte in LittleEndian - the same as BE because its only 1 byte*/
068:            public byte readByteLE() throws IOException {
069:                return inputStream.readByte();
070:            }
071:
072:            /** read a byte in LittleEndian - the same as BE because its only 1 byte*/
073:            public void readByteLEnum(byte[] b) throws IOException {
074:                inputStream.readFully(b);
075:            }
076:
077:            /** read a byte in BigEndian - the same as LE because its only 1 byte.  returns int as per java.io.DataStream*/
078:            public int readUnsignedByteBE() throws IOException {
079:                return inputStream.readUnsignedByte();
080:            }
081:
082:            /** read a byte in LittleEndian - the same as BE because its only 1 byte.  returns int as per java.io.DataStream*/
083:            public int readUnsignedByteLE() throws IOException {
084:                return inputStream.readUnsignedByte();
085:            }
086:
087:            /** read a 16bit short in BE*/
088:            public short readShortBE() throws IOException {
089:                return inputStream.readShort();
090:            }
091:
092:            /** read a 16bit short in LE*/
093:            public short readShortLE() throws IOException {
094:                inputStream.readFully(workSpace, 0, 2);
095:
096:                return (short) (((workSpace[1] & 0xff) << 8) | (workSpace[0] & 0xff));
097:            }
098:
099:            /** read a 32bit int in BE*/
100:            public int readIntBE() throws IOException {
101:                return inputStream.readInt();
102:            }
103:
104:            /** read a 32bit int in LE*/
105:            public int readIntLE() throws IOException {
106:                inputStream.readFully(workSpace, 0, 4);
107:
108:                return ((workSpace[3] & 0xff) << 24)
109:                        | ((workSpace[2] & 0xff) << 16)
110:                        | ((workSpace[1] & 0xff) << 8) | (workSpace[0] & 0xff);
111:            }
112:
113:            /** read a 64bit long  in BE*/
114:            public long readLongBE() throws IOException {
115:                return inputStream.readLong();
116:            }
117:
118:            /** read a 64bit long  in LE*/
119:            public long readLongLE() throws IOException {
120:                inputStream.readFully(workSpace, 0, 8);
121:
122:                return ((long) (workSpace[7] & 0xff) << 56)
123:                        | ((long) (workSpace[6] & 0xff) << 48)
124:                        | ((long) (workSpace[5] & 0xff) << 40)
125:                        | ((long) (workSpace[4] & 0xff) << 32)
126:                        | ((long) (workSpace[3] & 0xff) << 24)
127:                        | ((long) (workSpace[2] & 0xff) << 16)
128:                        | ((long) (workSpace[1] & 0xff) << 8)
129:                        | ((long) (workSpace[0] & 0xff));
130:            }
131:
132:            /** read a 64bit double  in BE*/
133:            public double readDoubleBE() throws IOException {
134:                return inputStream.readDouble();
135:            }
136:
137:            /** read a 64bit double  in LE*/
138:            public double readDoubleLE() throws IOException {
139:                long l;
140:
141:                inputStream.readFully(workSpace, 0, 8);
142:                l = ((long) (workSpace[7] & 0xff) << 56)
143:                        | ((long) (workSpace[6] & 0xff) << 48)
144:                        | ((long) (workSpace[5] & 0xff) << 40)
145:                        | ((long) (workSpace[4] & 0xff) << 32)
146:                        | ((long) (workSpace[3] & 0xff) << 24)
147:                        | ((long) (workSpace[2] & 0xff) << 16)
148:                        | ((long) (workSpace[1] & 0xff) << 8)
149:                        | ((long) (workSpace[0] & 0xff));
150:
151:                return Double.longBitsToDouble(l);
152:            }
153:
154:            /** skip ahead in the stream
155:             * @param num number of bytes to read ahead
156:             */
157:            public int skipBytes(int num) throws IOException {
158:                return inputStream.skipBytes(num);
159:            }
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.