01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17:
18: package org.apache.poi.hdf.extractor;
19:
20: /**
21: * Comment me
22: *
23: * @author Ryan Ackley
24: */
25:
26: public class Utils {
27:
28: public static short convertBytesToShort(byte firstByte,
29: byte secondByte) {
30: return (short) convertBytesToInt((byte) 0, (byte) 0, firstByte,
31: secondByte);
32: }
33:
34: public static int convertBytesToInt(byte firstByte,
35: byte secondByte, byte thirdByte, byte fourthByte) {
36: int firstInt = 0xff & firstByte;
37: int secondInt = 0xff & secondByte;
38: int thirdInt = 0xff & thirdByte;
39: int fourthInt = 0xff & fourthByte;
40:
41: return (firstInt << 24) | (secondInt << 16) | (thirdInt << 8)
42: | fourthInt;
43: }
44:
45: public static short convertBytesToShort(byte[] array, int offset) {
46: return convertBytesToShort(array[offset + 1], array[offset]);
47: }
48:
49: public static int convertBytesToInt(byte[] array, int offset) {
50: return convertBytesToInt(array[offset + 3], array[offset + 2],
51: array[offset + 1], array[offset]);
52: }
53:
54: public static int convertUnsignedByteToInt(byte b) {
55: return (0xff & b);
56: }
57:
58: public static char getUnicodeCharacter(byte[] array, int offset) {
59: return (char) convertBytesToShort(array, offset);
60: }
61:
62: }
|