1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 /**
29  *  Contains common static methods and contants for use within the package.
30  *
31  *  @author    Herbie Ong
32  */
33 
34 public final class PDBUtil {
35 
36     /** difference in seconds from Jan 01, 1904 to Jan 01, 1970 */
37     final static long TIME_DIFF = 2082844800;
38 
39     /** encoding scheme used */
40     final static String ENCODING = "8859_1";
41 
42     /** size of a pdb header in bytes */
43     final static int HEADER_SIZE = 78;
44 
45     /**
46      *  This method converts a 4 letter string into the Palm ID integer.
47      *
48      *  It is normally used to convert the Palm creator ID string into
49      *  the integer version of it.  Also use for data types, etc.
50      *
51      *  @param   s    4 character string.
52      *  @return   int    Palm ID representing the string.
53      *  @throws   ArrayIndexOutOfBoundsException    if string parameter
54      *                contains less than 4 characters.
55      */
56 
57     public static int intID(String s) {
58 
59         int id = -1;
60         int temp = 0;
61 
62         // grab the first char and put it in the high bits
63         // note that we only want 8 lower bits of it.
64         temp = (int) s.charAt(0);
65         id = temp << 24;
66 
67         // grab the second char and add it in.
68         temp = ((int) s.charAt(1)) & 0x00ff;
69         id += temp << 16;
70 
71         // grab the second char and add it in.
72         temp = ((int) s.charAt(2)) & 0x00ff;
73         id += temp << 8;
74 
75         // grab the last char and add it in
76         id += ((int) s.charAt(3)) & 0x00ff;
77 
78         return id;
79     }
80 
81     /**
82      *  This method converts an integer into a String given
83      *  the Palm ID format.
84      *
85      *  @param  i   Palm id.
86      *  @return  String   string representation.
87      */
88 
89     public static String stringID(int i) {
90 
91         char ch[] = new char[4];
92         ch[0] = (char) (i >>> 24);
93         ch[1] = (char) ((i >> 16) & 0x00ff);
94         ch[2] = (char) ((i >> 8) & 0x00ff);
95         ch[3] = (char) (i & 0x00ff);
96 
97         return new String(ch);
98     }
99 }
100 
101