Merge branch 'Jalview-BH/JAL-3026-JAL-3063-JAXB' of
[jalview.git] / unused / javajs / util / CompoundDocDirEntry.java
1 /* $RCSfile$
2  * $Author$
3  * $Date$
4  * $Revision$
5  *
6  * Some portions of this file have been modified by Robert Hanson hansonr.at.stolaf.edu 2012-2017
7  * for use in SwingJS via transpilation into JavaScript using Java2Script.
8  *
9  * Copyright (C) 2011  The Jmol Development Team
10  *
11  * Contact: jmol-developers@lists.sf.net
12  *
13  *  This library is free software; you can redistribute it and/or
14  *  modify it under the terms of the GNU Lesser General Public
15  *  License as published by the Free Software Foundation; either
16  *  version 2.1 of the License, or (at your option) any later version.
17  *
18  *  This library is distributed in the hope that it will be useful,
19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  *  Lesser General Public License for more details.
22  *
23  *  You should have received a copy of the GNU Lesser General Public
24  *  License along with this library; if not, write to the Free Software
25  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26  *  02110-1301, USA.
27  */
28
29 package javajs.util;
30
31
32 class CompoundDocDirEntry {
33
34   private final CompoundDocument cd;
35
36   /**
37    * @param compoundDocument
38    */
39   CompoundDocDirEntry(CompoundDocument compoundDocument) {
40     cd = compoundDocument;
41   }
42
43   // 128 bytes
44   //offset 0:
45   byte[] unicodeName64 = new byte[64];
46   short nBytesUnicodeName; // twice the ascii length, including terminating 0
47   byte entryType; // 0 empty; 1 storage; 2 stream; 5 root storage
48   //byte entryColor; // 0 red or 1 black
49   //int DIDchildLeft;
50   //int DIDchildRight;
51   //int DIDstorageRoot;
52   byte[] uniqueID16 = new byte[16];
53   byte[] userflags4 = new byte[4];
54   //long timeStamp1;
55   //long timeStamp2;
56   //offset 116:
57   int SIDfirstSector; // either SAT or SSAT
58   int lenStream;
59   byte[] unused = new byte[8];
60
61   // derived:
62
63   String entryName;
64   boolean isStandard;
65   boolean isEmpty;
66
67   final boolean readData() {
68     try {
69       cd.readByteArray(unicodeName64, 0, 64);
70       nBytesUnicodeName = cd.readShort();
71       entryType = cd.readByte();
72       /*entryColor = */cd.readByte();
73       /*DIDchildLeft = */cd.readInt();
74       /*DIDchildRight = */cd.readInt();
75       /*DIDstorageRoot = */cd.readInt();
76       cd.readByteArray(uniqueID16, 0, 16);
77       cd.readByteArray(userflags4, 0, 4);
78       /*timeStamp1 = */      cd.readByteArray(unused, 0, 8);//cd.readLong();
79       /*timeStamp2 = */      cd.readByteArray(unused, 0, 8);//cd.readLong();
80       //offset 116:
81       SIDfirstSector = cd.readInt();
82       lenStream = cd.readInt();
83       cd.readByteArray(unused, 0, 4);
84     } catch (Exception e) {
85       System.out.println(e.toString());
86       return false;
87     }
88     entryName = "";
89     for (int i = 0; i < nBytesUnicodeName - 2; i += 2)
90       entryName += (char) unicodeName64[i];
91     isStandard = (entryType == 5 || lenStream >= cd.header.minBytesStandardStream);
92     isEmpty = (entryType == 0 || lenStream <= 0);
93     //System.out.println(entryName + " type " + entryType);
94     return true;
95   }
96   
97   @Override
98   public String toString() {
99     return entryName + " " + lenStream;
100   }
101 }