Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / src / javajs / util / CompoundDocDirEntry.java
1 /* $RCSfile$
2  * $Author$
3  * $Date$
4  * $Revision$
5  *
6  * Copyright (C) 2011  The Jmol Development Team
7  *
8  * Contact: jmol-developers@lists.sf.net
9  *
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.
14  *
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.
19  *
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
23  *  02110-1301, USA.
24  */
25
26 package javajs.util;
27
28
29 class CompoundDocDirEntry {
30
31   private final CompoundDocument cd;
32
33   /**
34    * @param compoundDocument
35    */
36   CompoundDocDirEntry(CompoundDocument compoundDocument) {
37     cd = compoundDocument;
38   }
39
40   // 128 bytes
41   //offset 0:
42   byte[] unicodeName64 = new byte[64];
43   short nBytesUnicodeName; // twice the ascii length, including terminating 0
44   byte entryType; // 0 empty; 1 storage; 2 stream; 5 root storage
45   //byte entryColor; // 0 red or 1 black
46   //int DIDchildLeft;
47   //int DIDchildRight;
48   //int DIDstorageRoot;
49   byte[] uniqueID16 = new byte[16];
50   byte[] userflags4 = new byte[4];
51   //long timeStamp1;
52   //long timeStamp2;
53   //offset 116:
54   int SIDfirstSector; // either SAT or SSAT
55   int lenStream;
56   byte[] unused = new byte[8];
57
58   // derived:
59
60   String entryName;
61   boolean isStandard;
62   boolean isEmpty;
63
64   final boolean readData() {
65     try {
66       cd.readByteArray(unicodeName64, 0, 64);
67       nBytesUnicodeName = cd.readShort();
68       entryType = cd.readByte();
69       /*entryColor = */cd.readByte();
70       /*DIDchildLeft = */cd.readInt();
71       /*DIDchildRight = */cd.readInt();
72       /*DIDstorageRoot = */cd.readInt();
73       cd.readByteArray(uniqueID16, 0, 16);
74       cd.readByteArray(userflags4, 0, 4);
75       /*timeStamp1 = */      cd.readByteArray(unused, 0, 8);//cd.readLong();
76       /*timeStamp2 = */      cd.readByteArray(unused, 0, 8);//cd.readLong();
77       //offset 116:
78       SIDfirstSector = cd.readInt();
79       lenStream = cd.readInt();
80       cd.readByteArray(unused, 0, 4);
81     } catch (Exception e) {
82       System.out.println(e.toString());
83       return false;
84     }
85     entryName = "";
86     for (int i = 0; i < nBytesUnicodeName - 2; i += 2)
87       entryName += (char) unicodeName64[i];
88     isStandard = (entryType == 5 || lenStream >= cd.header.minBytesStandardStream);
89     isEmpty = (entryType == 0 || lenStream <= 0);
90     //System.out.println(entryName + " type " + entryType);
91     return true;
92   }
93 }