Source Code Cross Referenced for SignedBinary.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » impl » drda » 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 » db derby 10.2 » org.apache.derby.impl.drda 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derby.iapi.services.cache.SignedBinary
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to You under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           the License.  You may obtain a copy of the License at
011:
012:              http://www.apache.org/licenses/LICENSE-2.0
013:
014:           Unless required by applicable law or agreed to in writing, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:        package org.apache.derby.impl.drda;
022:
023:        /**
024:         * Converters from signed binary bytes to Java <code>short</code>, <code>int</code>, or <code>long</code>.
025:         */
026:        class SignedBinary {
027:            // Hide the default constructor, this is a static class.
028:            private SignedBinary() {
029:            }
030:
031:            /**
032:             * AS/400, Unix, System/390 byte-order for signed binary representations.
033:             */
034:            public final static int BIG_ENDIAN = 1;
035:
036:            /**
037:             * Intel 80/86 reversed byte-order for signed binary representations.
038:             */
039:            public final static int LITTLE_ENDIAN = 2;
040:
041:            /**
042:             * Build a Java short from a 2-byte signed binary representation.
043:             * <p>
044:             * Depending on machine type, byte orders are
045:             * {@link #BIG_ENDIAN BIG_ENDIAN} for signed binary integers, and
046:             * {@link #LITTLE_ENDIAN LITTLE_ENDIAN} for pc8087 signed binary integers.
047:             *
048:             * @exception IllegalArgumentException if the specified byte order is not recognized.
049:             */
050:            public static short getShort(byte[] buffer, int offset,
051:                    int byteOrder) {
052:                switch (byteOrder) {
053:                case BIG_ENDIAN:
054:                    return bigEndianBytesToShort(buffer, offset);
055:                case LITTLE_ENDIAN:
056:                    return littleEndianBytesToShort(buffer, offset);
057:                default:
058:                    throw new java.lang.IllegalArgumentException();
059:                }
060:            }
061:
062:            /**
063:             * Build a Java int from a 4-byte signed binary representation.
064:             * <p>
065:             * Depending on machine type, byte orders are
066:             * {@link #BIG_ENDIAN BIG_ENDIAN} for signed binary integers, and
067:             * {@link #LITTLE_ENDIAN LITTLE_ENDIAN} for pc8087 signed binary integers.
068:             *
069:             * @exception IllegalArgumentException if the specified byte order is not recognized.
070:             */
071:            public static int getInt(byte[] buffer, int offset, int byteOrder) {
072:                switch (byteOrder) {
073:                case BIG_ENDIAN:
074:                    return bigEndianBytesToInt(buffer, offset);
075:                case LITTLE_ENDIAN:
076:                    return littleEndianBytesToInt(buffer, offset);
077:                default:
078:                    throw new java.lang.IllegalArgumentException();
079:                }
080:            }
081:
082:            /**
083:             * Build a Java long from an 8-byte signed binary representation.
084:             * <p>
085:             * Depending on machine type, byte orders are
086:             * {@link #BIG_ENDIAN BIG_ENDIAN} for signed binary integers, and
087:             * {@link #LITTLE_ENDIAN LITTLE_ENDIAN} for pc8087 signed binary integers.
088:             * <p>
089:             *
090:             * @exception IllegalArgumentException if the specified byte order is not recognized.
091:             */
092:            public static long getLong(byte[] buffer, int offset, int byteOrder) {
093:                switch (byteOrder) {
094:                case BIG_ENDIAN:
095:                    return bigEndianBytesToLong(buffer, offset);
096:                case LITTLE_ENDIAN:
097:                    return littleEndianBytesToLong(buffer, offset);
098:                default:
099:                    throw new java.lang.IllegalArgumentException();
100:                }
101:            }
102:
103:            /**
104:             * Build a Java short from a 2-byte big endian signed binary representation.
105:             */
106:            public static short bigEndianBytesToShort(byte[] buffer, int offset) {
107:                return (short) (((buffer[offset + 0] & 0xff) << 8) + ((buffer[offset + 1] & 0xff) << 0));
108:            }
109:
110:            /**
111:             * Build a Java short from a 2-byte little endian signed binary representation.
112:             */
113:            public static short littleEndianBytesToShort(byte[] buffer,
114:                    int offset) {
115:                return (short) (((buffer[offset + 0] & 0xff) << 0) + ((buffer[offset + 1] & 0xff) << 8));
116:            }
117:
118:            /**
119:             * Build a Java int from a 4-byte big endian signed binary representation.
120:             */
121:            public static int bigEndianBytesToInt(byte[] buffer, int offset) {
122:                return (int) (((buffer[offset + 0] & 0xff) << 24)
123:                        + ((buffer[offset + 1] & 0xff) << 16)
124:                        + ((buffer[offset + 2] & 0xff) << 8) + ((buffer[offset + 3] & 0xff) << 0));
125:            }
126:
127:            /**
128:             * Build a Java int from a 4-byte little endian signed binary representation.
129:             */
130:            public static int littleEndianBytesToInt(byte[] buffer, int offset) {
131:                return (int) (((buffer[offset + 0] & 0xff) << 0)
132:                        + ((buffer[offset + 1] & 0xff) << 8)
133:                        + ((buffer[offset + 2] & 0xff) << 16) + ((buffer[offset + 3] & 0xff) << 24));
134:            }
135:
136:            /**
137:             * Build a Java long from an 8-byte big endian signed binary representation.
138:             */
139:            public static long bigEndianBytesToLong(byte[] buffer, int offset) {
140:                return (long) (((buffer[offset + 0] & 0xffL) << 56)
141:                        + ((buffer[offset + 1] & 0xffL) << 48)
142:                        + ((buffer[offset + 2] & 0xffL) << 40)
143:                        + ((buffer[offset + 3] & 0xffL) << 32)
144:                        + ((buffer[offset + 4] & 0xffL) << 24)
145:                        + ((buffer[offset + 5] & 0xffL) << 16)
146:                        + ((buffer[offset + 6] & 0xffL) << 8) + ((buffer[offset + 7] & 0xffL) << 0));
147:            }
148:
149:            /**
150:             * Build a Java long from an 8-byte little endian signed binary representation.
151:             */
152:            public static long littleEndianBytesToLong(byte[] buffer, int offset) {
153:                return (long) (((buffer[offset + 0] & 0xffL) << 0)
154:                        + ((buffer[offset + 1] & 0xffL) << 8)
155:                        + ((buffer[offset + 2] & 0xffL) << 16)
156:                        + ((buffer[offset + 3] & 0xffL) << 24)
157:                        + ((buffer[offset + 4] & 0xffL) << 32)
158:                        + ((buffer[offset + 5] & 0xffL) << 40)
159:                        + ((buffer[offset + 6] & 0xffL) << 48) + ((buffer[offset + 7] & 0xffL) << 56));
160:            }
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.