1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.xmerge.converter.palm; 25 26 /** 27 * Contains common static methods and constants for use within the package. 28 * 29 * @author Herbie Ong 30 */ 31 public final class PdbUtil { 32 33 /** Difference in seconds from Jan 01, 1904 to Jan 01, 1970. */ 34 final static long TIME_DIFF = 2082844800; 35 36 /** Encoding scheme used. */ 37 final static String ENCODING = "8859_1"; 38 39 /** Size of a PDB header in bytes. */ 40 final static int HEADER_SIZE = 78; 41 42 43 /** 44 * <p>This method converts a 4 letter string into the Palm ID 45 * integer.</p> 46 * 47 * <p>It is normally used to convert the Palm creator ID string into 48 * the integer version of it. Also use for data types, etc.</p> 49 * 50 * @param s Four character <code>String</code>. 51 * 52 * @return Palm ID representing the <code>String</code>. 53 * 54 * @throws ArrayIndexOutOfBoundsException If <code>String</code> 55 * parameter contains less than four characters. 56 */ intID(String s)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 /** 83 * This method converts an integer into a <code>String</code> 84 * given the Palm ID format. 85 * 86 * @param i Palm ID. 87 * 88 * @return <code>String</code> representation. 89 */ stringID(int i)90 public static String stringID(int i) { 91 92 char ch[] = new char[4]; 93 ch[0] = (char) (i >>> 24); 94 ch[1] = (char) ((i >> 16) & 0x00ff); 95 ch[2] = (char) ((i >> 8) & 0x00ff); 96 ch[3] = (char) (i & 0x00ff); 97 98 return new String(ch); 99 } 100 } 101 102