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