LibreOffice Module xmerge (master) 1
PdbDecoder.java
Go to the documentation of this file.
1/*
2 * This file is part of the LibreOffice project.
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 */
18
19package org.openoffice.xmerge.converter.palm;
20
21import java.io.IOException;
22import java.io.ByteArrayInputStream;
23import java.io.DataInputStream;
24
51public final class PdbDecoder {
52
67 public PalmDB parse(byte[] b) throws IOException {
68
69 ByteArrayInputStream bais = new ByteArrayInputStream(b);
70 DataInputStream dis = new DataInputStream(bais);
71
72 // read the PDB header
73 PdbHeader header = new PdbHeader();
74 header.read(dis);
75
76 Record recArray[] = new Record[header.numRecords];
77 if (header.numRecords != 0) {
78
79 // read in the record indices + offsets
80 int recOffset[] = new int[header.numRecords];
81 byte recAttrs[] = new byte[header.numRecords];
82
83 for (int i = 0; i < header.numRecords; i++) {
84
85 recOffset[i] = dis.readInt();
86
87 // read in attributes (1 byte) + unique id (3 bytes)
88 // take away the unique id, store the attributes
89 int attr = dis.readInt();
90 recAttrs[i] = (byte) (attr >>> 24);
91 }
92
93 // read the records
94 int lastIndex = header.numRecords - 1;
95
96 for (int i = 0; i < lastIndex; i++) {
97
98 //dis.seek(recOffset[i]);
99 dis.reset();
100 int nBytesToSkip = recOffset[i];
101 while (nBytesToSkip > 0) {
102 nBytesToSkip -= dis.skip(nBytesToSkip);
103 }
104 int len = recOffset[i+1] - recOffset[i];
105 byte[] bytes = new byte[len];
106 dis.readFully(bytes);
107 recArray[i] = new Record(bytes, recAttrs[i]);
108 }
109
110 // last record
111 dis.reset();
112 int len = dis.available() - recOffset[lastIndex];
113 int nBytesToSkip = recOffset[lastIndex];
114 while (nBytesToSkip > 0) {
115 nBytesToSkip -= dis.skip(nBytesToSkip);
116 }
117 byte[] bytes = new byte[len];
118 dis.readFully(bytes);
119 recArray[lastIndex] = new Record(bytes, recAttrs[lastIndex]);
120 }
121
122 // create PalmDB and return it
123 PalmDB pdb = new PalmDB(header.pdbName, header.creatorID,
124 header.typeID, header.version, header.attribute, recArray);
125
126 return pdb;
127 }
128}
constexpr sal_Int8 header[]
This class contains data for a single Palm database for use during a conversion process.
Definition: PalmDB.java:59
Provides functionality to decode a PDB formatted file into a PalmDB object given an InputStream.
Definition: PdbDecoder.java:51
PalmDB parse(byte[] b)
This method decodes a PDB file into a PalmDB object.
Definition: PdbDecoder.java:67
Contains the raw bytes for a Record in a PDB.
Definition: Record.java:35
unsigned char byte
int i
std::vector< sal_uInt8 > bytes