1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.office.compound;
22
23 import org.millscript.office.endianness.EndianDecoder;
24
25 /**
26 *
27 */
28 public class DirectoryEntry {
29
30 private final int center;
31
32 private final byte colour;
33
34 private final int directoryID;
35
36 private final int left;
37
38 private final String name;
39
40 private final int right;
41
42 private final int streamSID;
43
44 private final int streamSize;
45
46 private final DirectoryEntryType type;
47
48 /**
49 *
50 * @param endianDecoder
51 * @param data
52 */
53 public DirectoryEntry( final EndianDecoder endianDecoder, final byte[] data, final int did ) {
54
55 this.directoryID = did;
56
57 final int firstByteOffset = did * 128;
58
59 final int nameLength = ( endianDecoder.decode2ByteInt( data, firstByteOffset + 64 ) >> 1 ) - 1;
60
61 if ( nameLength == -1 ) {
62 this.name = null;
63 } else {
64 final char[] chars = new char[ nameLength ];
65 for ( int i = 0; i < nameLength; i++ ) {
66 chars[ i ] = endianDecoder.decode2ByteChar( data, firstByteOffset + i * 2 );
67 }
68
69 this.name = new String( chars );
70 }
71
72 this.type = DirectoryEntryType.getType( data[ firstByteOffset + 66 ] );
73
74 this.colour = data[ firstByteOffset + 67 ];
75
76 this.left = endianDecoder.decode4ByteInt( data, firstByteOffset + 68 );
77
78 this.right = endianDecoder.decode4ByteInt( data, firstByteOffset + 72 );
79
80
81
82 this.center = endianDecoder.decode4ByteInt( data, firstByteOffset + 76 );
83
84 this.streamSID = endianDecoder.decode4ByteInt( data, firstByteOffset + 116 );
85
86 this.streamSize = endianDecoder.decode4ByteInt( data, firstByteOffset + 120 );
87 }
88
89 public int getCenter() {
90 return this.center;
91 }
92
93 /**
94 * @return Returns the directoryID.
95 */
96 public int getDirectoryID() {
97 return this.directoryID;
98 }
99
100 public int getLeft() {
101 return this.left;
102 }
103
104 public String getName() {
105 return this.name;
106 }
107
108 public int getRight() {
109 return this.right;
110 }
111
112 public int getStreamSID() {
113 return this.streamSID;
114 }
115
116 public int getStreamSize() {
117 return this.streamSize;
118 }
119
120 public DirectoryEntryType getType() {
121 return this.type;
122 }
123
124 /**
125 * @see java.lang.Object#toString()
126 */
127 @Override
128 public String toString() {
129 final StringBuilder builder = new StringBuilder();
130 builder.append( this.directoryID );
131 builder.append( ": " );
132 builder.append( this.name );
133 return builder.toString();
134 }
135
136 }