1*04ea5bd4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*04ea5bd4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*04ea5bd4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*04ea5bd4SAndrew Rist  * distributed with this work for additional information
6*04ea5bd4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*04ea5bd4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*04ea5bd4SAndrew Rist  * "License"); you may not use this file except in compliance
9*04ea5bd4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*04ea5bd4SAndrew Rist  *
11*04ea5bd4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*04ea5bd4SAndrew Rist  *
13*04ea5bd4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*04ea5bd4SAndrew Rist  * software distributed under the License is distributed on an
15*04ea5bd4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*04ea5bd4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*04ea5bd4SAndrew Rist  * specific language governing permissions and limitations
18*04ea5bd4SAndrew Rist  * under the License.
19*04ea5bd4SAndrew Rist  *
20*04ea5bd4SAndrew Rist  *************************************************************/
21*04ea5bd4SAndrew Rist 
22*04ea5bd4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir /**
25cdf0e10cSrcweir  *  Contains common static methods and contants for use within the package.
26cdf0e10cSrcweir  *
27cdf0e10cSrcweir  *  @author    Herbie Ong
28cdf0e10cSrcweir  */
29cdf0e10cSrcweir 
30cdf0e10cSrcweir public final class PDBUtil {
31cdf0e10cSrcweir 
32cdf0e10cSrcweir     /** difference in seconds from Jan 01, 1904 to Jan 01, 1970 */
33cdf0e10cSrcweir     final static long TIME_DIFF = 2082844800;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir     /** encoding scheme used */
36cdf0e10cSrcweir     final static String ENCODING = "8859_1";
37cdf0e10cSrcweir 
38cdf0e10cSrcweir     /** size of a pdb header in bytes */
39cdf0e10cSrcweir     final static int HEADER_SIZE = 78;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir     /**
42cdf0e10cSrcweir      *  This method converts a 4 letter string into the Palm ID integer.
43cdf0e10cSrcweir      *
44cdf0e10cSrcweir      *  It is normally used to convert the Palm creator ID string into
45cdf0e10cSrcweir      *  the integer version of it.  Also use for data types, etc.
46cdf0e10cSrcweir      *
47cdf0e10cSrcweir      *  @param   s    4 character string.
48cdf0e10cSrcweir      *  @return   int    Palm ID representing the string.
49cdf0e10cSrcweir      *  @throws   ArrayIndexOutOfBoundsException    if string parameter
50cdf0e10cSrcweir      *                contains less than 4 characters.
51cdf0e10cSrcweir      */
52cdf0e10cSrcweir 
intID(String s)53cdf0e10cSrcweir     public static int intID(String s) {
54cdf0e10cSrcweir 
55cdf0e10cSrcweir         int id = -1;
56cdf0e10cSrcweir         int temp = 0;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir         // grab the first char and put it in the high bits
59cdf0e10cSrcweir         // note that we only want 8 lower bits of it.
60cdf0e10cSrcweir         temp = (int) s.charAt(0);
61cdf0e10cSrcweir         id = temp << 24;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir         // grab the second char and add it in.
64cdf0e10cSrcweir         temp = ((int) s.charAt(1)) & 0x00ff;
65cdf0e10cSrcweir         id += temp << 16;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir         // grab the second char and add it in.
68cdf0e10cSrcweir         temp = ((int) s.charAt(2)) & 0x00ff;
69cdf0e10cSrcweir         id += temp << 8;
70cdf0e10cSrcweir 
71cdf0e10cSrcweir         // grab the last char and add it in
72cdf0e10cSrcweir         id += ((int) s.charAt(3)) & 0x00ff;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir         return id;
75cdf0e10cSrcweir     }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     /**
78cdf0e10cSrcweir      *  This method converts an integer into a String given
79cdf0e10cSrcweir      *  the Palm ID format.
80cdf0e10cSrcweir      *
81cdf0e10cSrcweir      *  @param  i   Palm id.
82cdf0e10cSrcweir      *  @return  String   string representation.
83cdf0e10cSrcweir      */
84cdf0e10cSrcweir 
stringID(int i)85cdf0e10cSrcweir     public static String stringID(int i) {
86cdf0e10cSrcweir 
87cdf0e10cSrcweir         char ch[] = new char[4];
88cdf0e10cSrcweir         ch[0] = (char) (i >>> 24);
89cdf0e10cSrcweir         ch[1] = (char) ((i >> 16) & 0x00ff);
90cdf0e10cSrcweir         ch[2] = (char) ((i >> 8) & 0x00ff);
91cdf0e10cSrcweir         ch[3] = (char) (i & 0x00ff);
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         return new String(ch);
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
97