Source Code Cross Referenced for RecordStoreUtil.java in  » 6.0-JDK-Modules » j2me » com » sun » midp » rms » 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 » 6.0 JDK Modules » j2me » com.sun.midp.rms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         *
004:         * Portions Copyright  2000-2007 Sun Microsystems, Inc. All Rights
005:         * Reserved.  Use is subject to license terms.
006:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
007:         * 
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License version
010:         * 2 only, as published by the Free Software Foundation.
011:         * 
012:         * This program is distributed in the hope that it will be useful, but
013:         * WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * General Public License version 2 for more details (a copy is
016:         * included at /legal/license.txt).
017:         * 
018:         * You should have received a copy of the GNU General Public License
019:         * version 2 along with this work; if not, write to the Free Software
020:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
021:         * 02110-1301 USA
022:         * 
023:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
024:         * Clara, CA 95054 or visit www.sun.com if you need additional
025:         * information or have any questions.
026:         *
027:         * Copyright 2000 Motorola, Inc. All Rights Reserved.
028:         * This notice does not imply publication.
029:         */
030:
031:        package com.sun.midp.rms;
032:
033:        import javax.microedition.rms.RecordStoreException;
034:
035:        /**
036:         * A class implementing record store utility functions.
037:         */
038:
039:        public class RecordStoreUtil {
040:            /**
041:             * A convenience method for converting a byte array into
042:             * an int (assumes big-endian byte ordering).
043:             *
044:             * @param data the byte array returned from the database.
045:             * @param offset the offset into the array of the first byte to start from.
046:             *
047:             * @return an int corresponding to the first four bytes
048:             *         of the array passed in.
049:             */
050:            static int getInt(byte[] data, int offset) {
051:                int r = data[offset++];
052:                r = (r << 8) | ((int) (data[offset++]) & 0xff);
053:                r = (r << 8) | ((int) (data[offset++]) & 0xff);
054:                r = (r << 8) | ((int) (data[offset++]) & 0xff);
055:                return r;
056:            }
057:
058:            /**
059:             * A convenience method for converting a byte array into
060:             * a long (assumes big-endian byte ordering).
061:             *
062:             * @param data the byte array returned from the database.
063:             * @param offset the offset into the array of the first byte to start from.
064:             * @return a long corresponding to the first eight bytes
065:             *         of the array passed in.
066:             */
067:            static long getLong(byte[] data, int offset) {
068:                long r = data[offset++];
069:                r = (r << 8) | ((long) (data[offset++]) & 0xff);
070:                r = (r << 8) | ((long) (data[offset++]) & 0xff);
071:                r = (r << 8) | ((long) (data[offset++]) & 0xff);
072:                r = (r << 8) | ((long) (data[offset++]) & 0xff);
073:                r = (r << 8) | ((long) (data[offset++]) & 0xff);
074:                r = (r << 8) | ((long) (data[offset++]) & 0xff);
075:                r = (r << 8) | ((long) (data[offset++]) & 0xff);
076:                return r;
077:            }
078:
079:            /**
080:             * A convenience method for converting an integer into
081:             * a byte array.
082:             *
083:             * @param i the integer to turn into a byte array.
084:             * @param data a place to store the bytes of <code>i</code>.
085:             * @param offset starting point within <code>data<code> to
086:             *        store <code>i</code>.
087:             *
088:             * @return the number of bytes written to the array.
089:             */
090:            static int putInt(int i, byte[] data, int offset) {
091:                data[offset++] = (byte) ((i >> 24) & 0xff);
092:                data[offset++] = (byte) ((i >> 16) & 0xff);
093:                data[offset++] = (byte) ((i >> 8) & 0xff);
094:                data[offset] = (byte) (i & 0xff);
095:                return 4;
096:            }
097:
098:            /**
099:             * A convenience method for converting a long into
100:             * a byte array.
101:             *
102:             * @param l the <code>long<code> to turn into a byte array.
103:             * @param data a place to store the bytes of <code>l</code>.
104:             * @param offset Starting point within <code>data</code> to
105:             *        store <code>l</code>.
106:             *
107:             * @return the number of bytes written to the array.
108:             */
109:            static int putLong(long l, byte[] data, int offset) {
110:                data[offset++] = (byte) ((l >> 56) & 0xff);
111:                data[offset++] = (byte) ((l >> 48) & 0xff);
112:                data[offset++] = (byte) ((l >> 40) & 0xff);
113:                data[offset++] = (byte) ((l >> 32) & 0xff);
114:                data[offset++] = (byte) ((l >> 24) & 0xff);
115:                data[offset++] = (byte) ((l >> 16) & 0xff);
116:                data[offset++] = (byte) ((l >> 8) & 0xff);
117:                data[offset] = (byte) (l & 0xff);
118:                return 8;
119:            }
120:
121:            /**
122:             * A convenience method for calculating the block size given the data size.
123:             *
124:             * @param dataSize the size of the data in the block.
125:             *
126:             * @return an int corresponding to the size of the block padded to
127:             *         a multiple of the BLOCK HEADER SIZE.
128:             */
129:            static int calculateBlockSize(int dataSize) {
130:                final int block_header_size = AbstractRecordStoreImpl.BLOCK_HEADER_SIZE;
131:                int remainder = dataSize % block_header_size; // & 0x07;
132:
133:                if (remainder == 0) {
134:                    return dataSize + block_header_size;
135:                } else {
136:                    return dataSize + (block_header_size - remainder)
137:                            + block_header_size;
138:                }
139:            }
140:
141:            /**
142:             * Looks to see if the storage file for record store
143:             * identified by <code>uidPath</code> exists
144:             *
145:             * @param suiteId ID of the MIDlet suite that owns the record store
146:             * @param name name of the record store
147:             * @param extension the extension for the record store file
148:             *
149:             * @return true if the file exists, false if it does not.
150:             */
151:            native static boolean exists(int suiteId, String name, int extension);
152:
153:            /**
154:             * Removes the storage file for record store <code>filename</code>
155:             * if it exists.
156:             *
157:             * @param suiteId ID of the MIDlet suite that owns the record store
158:             * @param name name of the record store
159:             * @param extension the extension for the record store file
160:             *
161:             * @throws RecordStoreException if deletion encountered an error
162:             *         internally.
163:             */
164:            native static void deleteFile(int suiteId, String name,
165:                    int extension) throws RecordStoreException;
166:
167:            /**
168:             * Removes record store file without throwing an exception on failure.
169:             *
170:             * @param suiteId ID of the MIDlet suite that owns the record store
171:             * @param name name of the record store
172:             * @param extension the extension for the record store file
173:             *
174:             * @return <code>true</code> if file was found and deleted successfully,
175:             *         <code>false</code> otherwise.
176:             */
177:            static boolean quietDeleteFile(int suiteId, String name,
178:                    int extension) {
179:                try {
180:                    deleteFile(suiteId, name, extension);
181:                } catch (Throwable t) {
182:                    return false;
183:                }
184:                return true;
185:            }
186:
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.