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