6 * Copyright (C) 2011 The Jmol Development Team
8 * Contact: jmol-developers@lists.sf.net
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library 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 GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 class CompoundDocHeader {
34 private final CompoundDocument cd;
37 * @param compoundDocument
39 CompoundDocHeader(CompoundDocument compoundDocument) {
40 cd = compoundDocument;
45 byte[] magicNumbers = new byte[8]; // D0CF11E0A1B11AE1
46 byte[] uniqueID16 = new byte[16];
47 byte revNumber; // 3E = 62
51 //short byteOrder; // -2 littleEndian
52 short sectorPower; // 2^sectorPower = sector size; 512 = 2^9
53 short shortSectorPower; // 2^shortSectorPower = short sector size; 64 = 2^6
54 byte[] unused = new byte[10];
55 int nSATsectors; // number of sectors for sector allocation table
56 int SID_DIR_start; // sector identifier of start of directory sector
58 int minBytesStandardStream; // less than this (and not DIR) will be "short"
59 int SID_SSAT_start; // start of short sector allocation table (SSAT)
60 int nSSATsectors; // number of sectors allocated to SSAT
61 int SID_MSAT_next; // pointer to next master sector allocation table sector
62 int nAdditionalMATsectors; // number of sectors allocated to more MSAT sectors
63 //offset 76; 436 bytes:
64 int[] MSAT0 = new int[109]; // beginning of master allocation table
67 * Sector 0 is first sector AFTER this header
69 * If sectorPower = 9, then this allows for 109 PAGES
70 * of sector allocation tables, with 127 pointers per
71 * page (plus 1 pointer to the next SAT page), each
72 * pointing to a sector of 512 bytes. Thus, with no additional
73 * MSAT pages, the header allows for 109*128*512 = 7.1 Mb file
77 final boolean readData() {
79 cd.readByteArray(magicNumbers, 0, 8);
80 if (magicNumbers[0] != (byte) 0xD0 || magicNumbers[1] != (byte) 0xCF
81 || magicNumbers[2] != (byte) 0x11 || magicNumbers[3] != (byte) 0xE0
82 || magicNumbers[4] != (byte) 0xA1 || magicNumbers[5] != (byte) 0xB1
83 || magicNumbers[6] != (byte) 0x1A || magicNumbers[7] != (byte) 0xE1)
85 cd.readByteArray(uniqueID16, 0, 16);
86 revNumber = cd.readByte();
88 verNumber = cd.readByte();
90 byte b1 = cd.readByte();
91 byte b2 = cd.readByte();
92 cd.isBigEndian = (b1 == -1 && b2 == -2);
93 sectorPower = cd.readShort();
94 shortSectorPower = cd.readShort();
95 cd.readByteArray(unused, 0, 10);
96 nSATsectors = cd.readInt();
97 SID_DIR_start = cd.readInt();
98 cd.readByteArray(unused, 0, 4);
99 minBytesStandardStream = cd.readInt();
100 SID_SSAT_start = cd.readInt();
101 nSSATsectors = cd.readInt();
102 SID_MSAT_next = cd.readInt();
103 nAdditionalMATsectors = cd.readInt();
104 for (int i = 0; i < 109; i++)
105 MSAT0[i] = cd.readInt();
106 } catch (Exception e) {
107 System.out.println(e.toString());