Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / readers / DwgFileVR2004Reader.java @ 23641

History | View | Annotate | Download (101 KB)

1
/*
2
 * Created on 09-ene-2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44

    
45
package com.iver.cit.jdwglib.dwg.readers;
46

    
47
import java.io.IOException;
48
import java.nio.ByteBuffer;
49
import java.nio.ByteOrder;
50
import java.util.ArrayList;
51
import java.util.Comparator;
52
import java.util.List;
53
import java.util.TreeSet;
54

    
55
import org.apache.log4j.Logger;
56

    
57
import com.iver.cit.jdwglib.dwg.CorruptedDwgEntityException;
58
import com.iver.cit.jdwglib.dwg.DwgClass2004;
59
import com.iver.cit.jdwglib.dwg.DwgFile;
60
import com.iver.cit.jdwglib.dwg.DwgHandleReference;
61
import com.iver.cit.jdwglib.dwg.DwgObject;
62
import com.iver.cit.jdwglib.dwg.DwgObjectFactory;
63
import com.iver.cit.jdwglib.dwg.DwgObjectOffset;
64
import com.iver.cit.jdwglib.dwg.DwgUtil;
65

    
66
/**
67
 * @author alzabord
68
 *
69
 * TODO To change the template for this generated type comment go to Window -
70
 * Preferences - Java - Code Style - Code Templates
71
 */
72
public class DwgFileVR2004Reader implements IDwgFileReader {
73

    
74
        protected DwgFile dwgFile;
75

    
76
        protected ByteBuffer bb;
77

    
78
        static byte[] magicNumber = null;
79

    
80
        private String version = "";
81

    
82
        private byte[] unknowSixBytes;
83

    
84
        private byte[] threeBytes0;
85

    
86
        private byte[] unknowTwoBytes;
87

    
88
        private byte[] eightyTwoBytes0;
89

    
90
        private byte[] encryptedData;
91

    
92
        private byte[] decryptedData;
93

    
94
        private String fileID = "";
95

    
96
        private int rootTreeNodeGap;
97

    
98
        private int lowermostLeftTreeNodeGap;
99

    
100
        private int lowermostRightTreeNodeGap;
101

    
102
        private int lastSectionId; // Last Section identifier
103

    
104
        private int lastSectionAddress; // Last Section Address
105

    
106
        private int SecondHeaderAddress; // Second Header Address
107

    
108
        private int gapAmount; // Number of Gaps
109

    
110
        private int sectionAmount; // Number of Sections
111

    
112
        private int sectionMapId; // Section Map identifier
113

    
114
        private int sectionMapAddress; // Section Map address
115

    
116
        private int sectionInfoId; // Section Info identifier
117

    
118
        private int sectionInfoIndex = 0; // Section Info identifier into the
119

    
120
        // Sections Array
121

    
122
        private int sectionArraySize;
123

    
124
        private int gapArraySize;
125

    
126
        private byte[] generatedSequence;
127

    
128
        private Section[] sections;
129

    
130
        private Gap[] gaps;
131

    
132
        static final int TYPE_SECTION_MAP = 1;
133

    
134
        static final int TYPE_SECTION_INFO = 2;
135

    
136
        private static Logger logger = Logger.getLogger(DwgFileVR2004Reader.class.getName());
137

    
138
        /**
139
         * Reads the DWG version 2004 format
140
         *
141
         * @param dwgFile
142
         *            Represents the DWG file that we want to read
143
         * @throws IOException
144
         *             When DWG file path is wrong
145
         */
146
        public void read(DwgFile dwgFile, ByteBuffer bb) throws IOException {
147

    
148
                this.dwgFile = dwgFile;
149
                this.bb = bb;
150

    
151
                readDwgR2004FileHeader(bb);
152
                readDwgR2004SectionMap(bb);
153
                readDwgR2004InfoSection(bb);
154
                readDwgR2004Headers(bb);
155
                readDwgR2004Classes(bb);
156
                readDwgR2004ObjectOffsets(bb);
157

    
158
                readDwgR2004Objects();
159

    
160
        }
161

    
162
        protected void readDwgR2004InfoSection(ByteBuffer bb) {
163
                int numDescriptions;
164

    
165
                int sizeOfSection;
166
                int numSections;
167
                int maxDecompressedSize;
168
                int compressed;
169
                int sectionType;
170
                int encrypted;
171
                String sectionName = "";
172

    
173
                int sectionNumber;
174
                int dataSize;
175
                int startOffset;
176

    
177
                char c;
178
                int pos;
179

    
180
                if (sectionInfoIndex == 0) {
181
                        logger.error("No se ha encontrado la Section Info en el array de secciones.");
182
                }
183

    
184
                pos = sections[sectionInfoIndex].getAddress(); // we get the address for the Section Info
185

    
186
                bb.position(pos);
187

    
188
                ByteBuffer dData = readSystemSection(bb);
189
                dData.order(ByteOrder.LITTLE_ENDIAN);
190
                dData.position(0);
191

    
192
                /*
193
                 * We start reading the Section Info once decompressed We will find data
194
                 * blocks depending on numDescriptions value
195
                 */
196
                numDescriptions = dData.getInt();
197
                dData.getInt(); // 0x02
198
                dData.getInt(); // 0x00007400
199
                dData.getInt(); // 0x00
200
                dData.getInt(); // unknown
201

    
202
                for (int i = 0; i < numDescriptions; i++) {
203
                        sizeOfSection = dData.getInt();
204
                        dData.getInt(); // unknown
205
                        numSections = dData.getInt();
206
                        maxDecompressedSize = dData.getInt();
207
                        dData.getInt(); // unknown
208
                        compressed = dData.getInt();
209
                        sectionType = dData.getInt();
210
                        encrypted = dData.getInt();
211
                        sectionName = "";
212
                        for (int j = 0; j < 64; j++) {
213
                                c = (char) dData.get();
214
                                sectionName = sectionName + c;
215
                        }
216

    
217
                        for (int k = 0; k < numSections; k++) {
218
                                sectionNumber = dData.getInt(); // index into the Sections Array
219
                                dataSize = dData.getInt();
220
                                startOffset = dData.getInt();
221
                                dData.getInt(); // unknown
222

    
223

    
224
                                // We set the name for the Section, so we can localize it by the name
225
                                for (int j = 0; j < sectionAmount; j++) {
226
                                        Section section = sections[j];
227
                                        if (section.getNumber() == sectionNumber) {
228
                                                section.setName(sectionName);
229
                                                section.setSizeOfLogicalSection(sizeOfSection);
230
                                                section.setDataSize(dataSize);
231
                                                section.setMaxDecompressedSize(maxDecompressedSize);
232
                                                section.setCompressed(compressed);
233
                                                section.setType(sectionType);
234
                                                section.setEncrypted(encrypted);
235
                                                section.setStartOffset(startOffset);
236
                                        }
237
                                }
238

    
239
                        }
240
                }
241
        }
242

    
243
        /**
244
         * This function reads the header section of the file, with the encrypted
245
         * data
246
         *
247
         * @param bb
248
         *            ByteBuffer containing the opened DWG file
249
         */
250
        protected void readDwgR2004FileHeader(ByteBuffer bb) {
251

    
252
                logger.info("STARTING TO READ DWG FILE.");
253
                bb.order(ByteOrder.LITTLE_ENDIAN);
254
                for (int i = 0; i < 6; i++) {
255
                        version = version + (char) bb.get();
256
                }
257
                if (!version.equalsIgnoreCase("AC1018")) {
258
                        logger.error("Error en la version: " + version);
259
                }
260

    
261
                /*
262
                 * OpenAlliance documentation says we will read 6 0x00 bytes but the
263
                 * sixth one is always 0x4C
264
                 */
265
                unknowSixBytes = new byte[6];
266
                int pos = 6;
267
                for (int i = 0; i < 5; i++) {
268
                        unknowSixBytes[i] = bb.get();
269
                        if (unknowSixBytes[i] != 0) {
270
                                logger.warn("(unknowSixBytes) En la posicion 0x"
271
                                                + Integer.toHexString(pos + i)
272
                                                + " deber?a haber un 0, pero hay un 0x"
273
                                                + Integer.toHexString(unknowSixBytes[i]));
274
                        }
275
                }
276
                pos = 0xB;
277
                unknowSixBytes[5] = bb.get();
278
                if (unknowSixBytes[5] != 0x4C) {
279
                        logger.warn("(unknowSixBytes) En la posicion 0x"
280
                                        + Integer.toHexString(pos)
281
                                        + " deber?a haber un 0x4C, pero hay un 0x"
282
                                        + Integer.toHexString(unknowSixBytes[5]));
283
                }
284

    
285
                bb.get(); // Unknown Byte
286
                bb.getInt(); // previewAddress
287
                bb.get(); // dwgVer
288
                bb.get(); // maintReleaseVer
289
                bb.getShort(); // codepage
290

    
291
                /*
292
                 * OpenAlliance documentation says we will read 3 0x00 bytes but what we
293
                 * always find is 0x00, 0x19 and then 0x4C
294
                 */
295
                threeBytes0 = new byte[3];
296
                pos = 0x15;
297
                bb.get(threeBytes0);
298
                if (threeBytes0[0] != 0x0) {
299
                        logger.warn("Posible error leyendo la cabecera del archivo DWG: " +
300
                                        "En la posicion 0x" + Integer.toHexString(pos)
301
                                        + " deber?a haber un 0x0, pero hay un 0x"
302
                                        + Integer.toHexString(threeBytes0[0]));
303
                }
304
                pos = 0x16;
305
                if (threeBytes0[1] != 0x19) {
306
                        logger.warn("Posible error leyendo la cabecera del archivo DWG: " +
307
                                        "En la posicion 0x" + Integer.toHexString(pos)
308
                                        + " deber?a haber un 0x19, pero hay un 0x"
309
                                        + Integer.toHexString(threeBytes0[1]));
310
                }
311
                pos = 0x17;
312
                if (threeBytes0[2] != 0x4C) {
313
                        logger.warn("Posible error leyendo la cabecera del archivo DWG: " +
314
                                        "En la posicion 0x" + Integer.toHexString(pos)
315
                                        + " deber?a haber un 0x4C, pero hay un 0x"
316
                                        + Integer.toHexString(threeBytes0[2]));
317
                }
318

    
319
                bb.getInt(); // security Type
320
                bb.getInt(); // unknownLong
321
                bb.getInt(); // dwgPropertyAddr
322
                bb.getInt(); // vbaProjectAddr
323
                bb.getInt(); // 0x00000080
324

    
325
                pos = 0x2C;
326

    
327
                unknowTwoBytes = new byte[2];
328
                for (int i = 0; i < 2; i++) {
329
                        unknowTwoBytes[i] = bb.get();
330
                }
331
                pos = 0x2E;
332
                eightyTwoBytes0 = new byte[82];
333
                for (int i = 0; i < eightyTwoBytes0.length; i++) {
334
                        eightyTwoBytes0[i] = bb.get();
335
                        if (eightyTwoBytes0[i] != 0) {
336
                                logger.warn("Posible error leyendo la cabecera del archivo DWG: " +
337
                                                "(eightyTwoBytes0) En la posicion 0x"
338
                                                + Integer.toHexString(pos + i)
339
                                                + " deber?a haber un 0, pero hay un 0x"
340
                                                + Integer.toHexString(eightyTwoBytes0[i]));
341
                        }
342
                }
343

    
344
                int len = 0x6C;
345
                encryptedData = new byte[len];
346
                decryptedData = new byte[len];
347
                if (magicNumber == null) {
348
                        DwgFileVR2004Reader.setMagicNumber();
349
                }
350

    
351
                // decryptedData will contain the decrypted sequence after xor'ing the
352
                // encrypted data
353
                for (int i = 0; i < len; i++) {
354
                        encryptedData[i] = bb.get();
355
                        decryptedData[i] = (byte) (encryptedData[i] ^ magicNumber[i]);
356
                }
357

    
358
                ByteBuffer decryptedDataBB = ByteBuffer.allocate(len);
359
                decryptedDataBB.put(decryptedData);
360
                decryptedDataBB.position(0);
361
                decryptedDataBB.order(ByteOrder.LITTLE_ENDIAN);
362

    
363
                // we start intercepting the decrypted variables
364
                for (int i = 0; i < 12; i++) {
365
                        fileID = fileID + (char) decryptedDataBB.get();
366
                }
367
                decryptedDataBB.getInt(); // 0x00
368

    
369
                decryptedDataBB.getInt(); // 0x6C
370

    
371
                decryptedDataBB.getInt(); // 0x04
372

    
373
                rootTreeNodeGap = decryptedDataBB.getInt();
374
                lowermostLeftTreeNodeGap = decryptedDataBB.getInt();
375
                lowermostRightTreeNodeGap = decryptedDataBB.getInt();
376
                decryptedDataBB.getInt(); // unknown
377
                lastSectionId = decryptedDataBB.getInt();
378

    
379
                lastSectionAddress = decryptedDataBB.getInt();
380
                decryptedDataBB.getInt(); // 0x00
381

    
382
                SecondHeaderAddress = decryptedDataBB.getInt();
383
                decryptedDataBB.getInt(); // 0x00
384

    
385
                gapAmount = decryptedDataBB.getInt();
386
                sectionAmount = decryptedDataBB.getInt(); // Very important: this is
387
                // the number of sections in the file
388
                decryptedDataBB.getInt(); // 0x20
389
                decryptedDataBB.getInt(); // 0x80
390
                decryptedDataBB.getInt(); // 0x40
391

    
392
                sectionMapId = decryptedDataBB.getInt();
393
                sectionMapAddress = decryptedDataBB.getInt() + 0x100; // the Section Map Address
394
                decryptedDataBB.getInt(); // 0x00
395
                sectionInfoId = decryptedDataBB.getInt(); // Very important: the id of the Section Info
396
                sectionArraySize = decryptedDataBB.getInt();
397
                gapArraySize = decryptedDataBB.getInt();
398
                decryptedDataBB.getInt(); // CRC
399
                len = 0x14;
400
                generatedSequence = new byte[len];
401
                bb.get(generatedSequence);
402
                // Done reading the encrypted variables
403

    
404
        }
405

    
406
        /*************************************************************************************
407
         * **********************************************************************/
408

    
409
        /**
410
         * Read and store all the header variables into the
411
         * <code> HeaderVars </code> Map
412
         *
413
         * @param bb
414
         *            ByteBuffer containing the opened DWG file
415
         */
416
        private void readDwgR2004Headers(ByteBuffer bb) {
417

    
418
                /*
419
                 * NOTA (Paco) He encontrado un sitio web con explicacion de ?todas?
420
                 * estas variables: http://www.hispacad.com/variables
421
                 */
422

    
423
                ByteBuffer decompressedBB = readSection(bb, "AcDb:Header");
424

    
425
                byte[] sentinel = new byte[16];
426
                decompressedBB.order(ByteOrder.nativeOrder());
427
                decompressedBB.position(0);
428
                decompressedBB.get(sentinel); // we get the sentinel that ALWAYS
429
                // appears before the data
430

    
431
                if ((sentinel[0] & 0xFF) != 0xcf)
432
                        logger.warn("sentinel[0] != 0xcf found " + (sentinel[0] & 0xFF));
433
                if ((sentinel[1] & 0xFF) != 0x7b)
434
                        logger.warn("sentinel[1] != 0x7b found " + (sentinel[1] & 0xFF));
435
                if ((sentinel[2] & 0xFF) != 0x1f)
436
                        logger.warn("sentinel[2] != 0x1f found " + (sentinel[2] & 0xFF));
437
                if ((sentinel[3] & 0xFF) != 0x23)
438
                        logger.warn("sentinel[3] != 0x23 found " + (sentinel[3] & 0xFF));
439
                if ((sentinel[4] & 0xFF) != 0xfd)
440
                        logger.warn("sentinel[4] != 0xfd found " + (sentinel[4] & 0xFF));
441
                if ((sentinel[5] & 0xFF) != 0xde)
442
                        logger.warn("sentinel[5] != 0xde found " + (sentinel[5] & 0xFF));
443
                if ((sentinel[6] & 0xFF) != 0x38)
444
                        logger.warn("sentinel[6] != 0x38 found " + (sentinel[6] & 0xFF));
445
                if ((sentinel[7] & 0xFF) != 0xa9)
446
                        logger.warn("sentinel[7] != 0xa9 found " + (sentinel[7] & 0xFF));
447
                if ((sentinel[8] & 0xFF) != 0x5f)
448
                        logger.warn("sentinel[8] != 0x5f found " + (sentinel[8] & 0xFF));
449
                if ((sentinel[9] & 0xFF) != 0x7c)
450
                        logger.warn("sentinel[9] != 0x7c found " + (sentinel[9] & 0xFF));
451
                if ((sentinel[10] & 0xFF) != 0x68)
452
                        logger.warn("sentinel[10] != 0x68 found " + (sentinel[10] & 0xFF));
453
                if ((sentinel[11] & 0xFF) != 0xb8)
454
                        logger.warn("sentinel[11] != 0xb8 found " + (sentinel[11] & 0xFF));
455
                if ((sentinel[12] & 0xFF) != 0x4e)
456
                        logger.warn("sentinel[12] != 0x4e found " + (sentinel[12] & 0xFF));
457
                if ((sentinel[13] & 0xFF) != 0x6d)
458
                        logger.warn("sentinel[13] != 0x6d found " + (sentinel[13] & 0xFF));
459
                if ((sentinel[14] & 0xFF) != 0x33)
460
                        logger.warn("sentinel[14] != 0x33 found " + (sentinel[14] & 0xFF));
461
                if ((sentinel[15] & 0xFF) != 0x5f)
462
                        logger.warn("sentinel[15] != 0x5f found " + (sentinel[15] & 0xFF));
463

    
464
                // we start working with data that comes after the beginning sentinel
465
                decompressedBB.order(ByteOrder.LITTLE_ENDIAN);
466
                int size = decompressedBB.getInt(); // this size is never correct
467

    
468
                decompressedBB.order(ByteOrder.nativeOrder());
469
                byte[] data = new byte[size];
470
                decompressedBB.get(data);
471

    
472
                int[] intData = DwgUtil.toIntArray(data);
473

    
474
                bb.order(ByteOrder.LITTLE_ENDIAN);
475
                decompressedBB.getShort(); // CRC
476

    
477
                decompressedBB.order(ByteOrder.nativeOrder());
478
                byte[] lastSentinnel = new byte[16]; // we know it comes there because we already found it
479
                decompressedBB.get(lastSentinnel);
480

    
481
                if ((lastSentinnel[0] & 0xFF) != 0x30)
482
                        logger.warn("lastSentinnel[0] != 0x30 , is: " + lastSentinnel[0]);
483
                if ((lastSentinnel[1] & 0xFF) != 0x84)
484
                        logger.warn("lastSentinnel[1] != 0x84 , is: " + lastSentinnel[1]);
485
                if ((lastSentinnel[2] & 0xFF) != 0xe0)
486
                        logger.warn("lastSentinnel[2] != 0xe0 , is: " + lastSentinnel[2]);
487
                if ((lastSentinnel[3] & 0xFF) != 0xdc)
488
                        logger.warn("lastSentinnel[3] != 0xdc , is: " + lastSentinnel[3]);
489
                if ((lastSentinnel[4] & 0xFF) != 0x02)
490
                        logger.warn("lastSentinnel[4] != 0x02 , is: " + lastSentinnel[4]);
491
                if ((lastSentinnel[5] & 0xFF) != 0x21)
492
                        logger.warn("lastSentinnel[5] != 0x21 , is: " + lastSentinnel[5]);
493
                if ((lastSentinnel[6] & 0xFF) != 0xc7)
494
                        logger.warn("lastSentinnel[6] != 0xc7 , is: " + lastSentinnel[6]);
495
                if ((lastSentinnel[7] & 0xFF) != 0x56)
496
                        logger.warn("lastSentinnel[7] != 0x56 , is: " + lastSentinnel[7]);
497
                if ((lastSentinnel[8] & 0xFF) != 0xa0)
498
                        logger.warn("lastSentinnel[8] != 0xa0 , is: " + lastSentinnel[8]);
499
                if ((lastSentinnel[9] & 0xFF) != 0x83)
500
                        logger.warn("lastSentinnel[9] != 0x83 , is: " + lastSentinnel[9]);
501
                if ((lastSentinnel[10] & 0xFF) != 0x97)
502
                        logger.warn("lastSentinnel[10] != 0x97 , is: " + lastSentinnel[10]);
503
                if ((lastSentinnel[11] & 0xFF) != 0x47)
504
                        logger.warn("lastSentinnel[11] != 0x47 , is: " + lastSentinnel[11]);
505
                if ((lastSentinnel[12] & 0xFF) != 0xb1)
506
                        logger.warn("lastSentinnel[12] != 0xb1 , is: " + lastSentinnel[12]);
507
                if ((lastSentinnel[13] & 0xFF) != 0x92)
508
                        logger.warn("lastSentinnel[13] != 0x92 , is: " + lastSentinnel[13]);
509
                if ((lastSentinnel[14] & 0xFF) != 0xcc)
510
                        logger.warn("lastSentinnel[14] != 0xcc , is: " + lastSentinnel[14]);
511
                if ((lastSentinnel[15] & 0xFF) != 0xa0)
512
                        logger.warn("lastSentinnel[15] != 0xa0 , is: " + lastSentinnel[15]);
513

    
514
                int bitPos = 0;
515
                try {
516

    
517
                        List val = DwgUtil.getBitDouble(intData, bitPos); // Unknown
518
                        bitPos = ((Integer) val.get(0)).intValue();
519
                        dwgFile.setHeader("VAL1", val.get(1));
520

    
521
                        val = DwgUtil.getBitDouble(intData, bitPos); // Unknown
522
                        bitPos = ((Integer) val.get(0)).intValue();
523
                        dwgFile.setHeader("VAL2", val.get(1));
524

    
525
                        val = DwgUtil.getBitDouble(intData, bitPos); // Unknown
526
                        bitPos = ((Integer) val.get(0)).intValue();
527
                        dwgFile.setHeader("VAL3", val.get(1));
528

    
529
                        val = DwgUtil.getBitDouble(intData, bitPos); // Unknown
530
                        bitPos = ((Integer) val.get(0)).intValue();
531
                        dwgFile.setHeader("VAL4", val.get(1));
532

    
533
                        val = DwgUtil.getTextString(intData, bitPos); // Unknown
534
                        bitPos = ((Integer) val.get(0)).intValue();
535
                        dwgFile.setHeader("STRING1", val.get(1));
536

    
537
                        val = DwgUtil.getTextString(intData, bitPos); // Unknown
538
                        bitPos = ((Integer) val.get(0)).intValue();
539
                        dwgFile.setHeader("STRING2", val.get(1));
540

    
541
                        val = DwgUtil.getTextString(intData, bitPos); // Unknown
542
                        bitPos = ((Integer) val.get(0)).intValue();
543
                        dwgFile.setHeader("STRING3", val.get(1));
544

    
545
                        val = DwgUtil.getTextString(intData, bitPos); // Unknown
546
                        bitPos = ((Integer) val.get(0)).intValue();
547
                        dwgFile.setHeader("STRING4", val.get(1));
548

    
549
                        val = DwgUtil.getBitLong(intData, bitPos); // Unknown
550
                        bitPos = ((Integer) val.get(0)).intValue();
551
                        dwgFile.setHeader("LONG1", val.get(1));
552

    
553
                        val = DwgUtil.getBitLong(intData, bitPos); // Unknown
554
                        bitPos = ((Integer) val.get(0)).intValue();
555
                        dwgFile.setHeader("LONG2", val.get(1));
556

    
557
                        val = DwgUtil.testBit(intData, bitPos);
558
                        bitPos = ((Integer) val.get(0)).intValue();
559
                        dwgFile.setHeader("DIMASO", val.get(1));
560

    
561
                        val = DwgUtil.testBit(intData, bitPos);
562
                        bitPos = ((Integer) val.get(0)).intValue();
563
                        dwgFile.setHeader("DIMSHO", val.get(1));
564

    
565
                        val = DwgUtil.testBit(intData, bitPos);
566
                        bitPos = ((Integer) val.get(0)).intValue();
567
                        dwgFile.setHeader("PLINEGEN", val.get(1));
568

    
569
                        val = DwgUtil.testBit(intData, bitPos);
570
                        bitPos = ((Integer) val.get(0)).intValue();
571
                        dwgFile.setHeader("ORTHOMODE", val.get(1));
572

    
573
                        val = DwgUtil.testBit(intData, bitPos);
574
                        bitPos = ((Integer) val.get(0)).intValue();
575
                        dwgFile.setHeader("REGENMODE", val.get(1));
576

    
577
                        val = DwgUtil.testBit(intData, bitPos);
578
                        bitPos = ((Integer) val.get(0)).intValue();
579
                        dwgFile.setHeader("FILLMODE", val.get(1));
580

    
581
                        val = DwgUtil.testBit(intData, bitPos);
582
                        bitPos = ((Integer) val.get(0)).intValue();
583
                        dwgFile.setHeader("QTEXTMODE", val.get(1));
584

    
585
                        val = DwgUtil.testBit(intData, bitPos);
586
                        bitPos = ((Integer) val.get(0)).intValue();
587
                        dwgFile.setHeader("PSLTSCALE", val.get(1));
588

    
589
                        val = DwgUtil.testBit(intData, bitPos);
590
                        bitPos = ((Integer) val.get(0)).intValue();
591
                        dwgFile.setHeader("LIMCHECK", val.get(1));
592

    
593
                        val = DwgUtil.testBit(intData, bitPos);
594
                        bitPos = ((Integer) val.get(0)).intValue();
595
                        dwgFile.setHeader("UNDOCUMENTED1", val.get(1));
596

    
597
                        val = DwgUtil.testBit(intData, bitPos);
598
                        bitPos = ((Integer) val.get(0)).intValue();
599
                        dwgFile.setHeader("USER_TIMER", val.get(1));
600

    
601
                        val = DwgUtil.testBit(intData, bitPos);
602
                        bitPos = ((Integer) val.get(0)).intValue();
603
                        dwgFile.setHeader("SKPOLY", val.get(1));
604

    
605
                        val = DwgUtil.testBit(intData, bitPos);
606
                        bitPos = ((Integer) val.get(0)).intValue();
607
                        dwgFile.setHeader("ANGDIR", val.get(1));
608

    
609
                        val = DwgUtil.testBit(intData, bitPos);
610
                        bitPos = ((Integer) val.get(0)).intValue();
611
                        dwgFile.setHeader("SPLFRAME", val.get(1));
612

    
613
                        val = DwgUtil.testBit(intData, bitPos);
614
                        bitPos = ((Integer) val.get(0)).intValue();
615
                        dwgFile.setHeader("MIRRTEXT", val.get(1));
616

    
617
                        val = DwgUtil.testBit(intData, bitPos);
618
                        bitPos = ((Integer) val.get(0)).intValue();
619
                        dwgFile.setHeader("WORLDVIEW", val.get(1));
620

    
621
                        val = DwgUtil.testBit(intData, bitPos);
622
                        bitPos = ((Integer) val.get(0)).intValue();
623
                        dwgFile.setHeader("TILEMODE", val.get(1));
624

    
625
                        val = DwgUtil.testBit(intData, bitPos);
626
                        bitPos = ((Integer) val.get(0)).intValue();
627
                        dwgFile.setHeader("PLIMCHECK", val.get(1));
628

    
629
                        val = DwgUtil.testBit(intData, bitPos);
630
                        bitPos = ((Integer) val.get(0)).intValue();
631
                        dwgFile.setHeader("VISRETAIN", val.get(1));
632

    
633
                        val = DwgUtil.testBit(intData, bitPos);
634
                        bitPos = ((Integer) val.get(0)).intValue();
635
                        dwgFile.setHeader("DISPSILH", val.get(1));
636

    
637
                        val = DwgUtil.testBit(intData, bitPos);
638
                        bitPos = ((Integer) val.get(0)).intValue();
639
                        dwgFile.setHeader("PELLISE", val.get(1));
640

    
641
                        val = DwgUtil.getBitShort(intData, bitPos);
642
                        bitPos = ((Integer) val.get(0)).intValue();
643
                        dwgFile.setHeader("PROXYGRAPH", val.get(1));
644

    
645
                        val = DwgUtil.getBitShort(intData, bitPos);
646
                        bitPos = ((Integer) val.get(0)).intValue();
647
                        dwgFile.setHeader("TREEDEPTH", val.get(1));
648

    
649
                        val = DwgUtil.getBitShort(intData, bitPos);
650
                        bitPos = ((Integer) val.get(0)).intValue();
651
                        dwgFile.setHeader("LUNITS", val.get(1));
652

    
653
                        val = DwgUtil.getBitShort(intData, bitPos);
654
                        bitPos = ((Integer) val.get(0)).intValue();
655
                        dwgFile.setHeader("LUPREC", val.get(1));
656

    
657
                        val = DwgUtil.getBitShort(intData, bitPos);
658
                        bitPos = ((Integer) val.get(0)).intValue();
659
                        dwgFile.setHeader("AUNITS", val.get(1));
660

    
661
                        val = DwgUtil.getBitShort(intData, bitPos);
662
                        bitPos = ((Integer) val.get(0)).intValue();
663
                        dwgFile.setHeader("AUPREC", val.get(1));
664

    
665
                        val = DwgUtil.getBitShort(intData, bitPos);
666
                        bitPos = ((Integer) val.get(0)).intValue();
667
                        dwgFile.setHeader("ATTMODE", val.get(1));
668

    
669
                        val = DwgUtil.getBitShort(intData, bitPos);
670
                        bitPos = ((Integer) val.get(0)).intValue();
671
                        dwgFile.setHeader("PDMODE", val.get(1));
672

    
673
                        val = DwgUtil.getBitLong(intData, bitPos);
674
                        bitPos = ((Integer) val.get(0)).intValue();
675
                        dwgFile.setHeader("UNKNOWN1", val.get(1));
676

    
677
                        val = DwgUtil.getBitLong(intData, bitPos);
678
                        bitPos = ((Integer) val.get(0)).intValue();
679
                        dwgFile.setHeader("UNKNOWN2", val.get(1));
680

    
681
                        val = DwgUtil.getBitLong(intData, bitPos);
682
                        bitPos = ((Integer) val.get(0)).intValue();
683
                        dwgFile.setHeader("UNKNOWN3", val.get(1));
684

    
685
                        val = DwgUtil.getBitShort(intData, bitPos);
686
                        bitPos = ((Integer) val.get(0)).intValue();
687
                        dwgFile.setHeader("USERI1", val.get(1));
688

    
689
                        val = DwgUtil.getBitShort(intData, bitPos);
690
                        bitPos = ((Integer) val.get(0)).intValue();
691
                        dwgFile.setHeader("USERI2", val.get(1));
692

    
693
                        val = DwgUtil.getBitShort(intData, bitPos);
694
                        bitPos = ((Integer) val.get(0)).intValue();
695
                        dwgFile.setHeader("USERI3", val.get(1));
696

    
697
                        val = DwgUtil.getBitShort(intData, bitPos);
698
                        bitPos = ((Integer) val.get(0)).intValue();
699
                        dwgFile.setHeader("USERI4", val.get(1));
700

    
701
                        val = DwgUtil.getBitShort(intData, bitPos);
702
                        bitPos = ((Integer) val.get(0)).intValue();
703
                        dwgFile.setHeader("USERI5", val.get(1));
704

    
705
                        val = DwgUtil.getBitShort(intData, bitPos);
706
                        bitPos = ((Integer) val.get(0)).intValue();
707
                        dwgFile.setHeader("SPLINESEGS", val.get(1));
708

    
709
                        val = DwgUtil.getBitShort(intData, bitPos);
710
                        bitPos = ((Integer) val.get(0)).intValue();
711
                        dwgFile.setHeader("SURFU", val.get(1));
712

    
713
                        val = DwgUtil.getBitShort(intData, bitPos);
714
                        bitPos = ((Integer) val.get(0)).intValue();
715
                        dwgFile.setHeader("SURFV", val.get(1));
716

    
717
                        val = DwgUtil.getBitShort(intData, bitPos);
718
                        bitPos = ((Integer) val.get(0)).intValue();
719
                        dwgFile.setHeader("SURFTYPE", val.get(1));
720

    
721
                        val = DwgUtil.getBitShort(intData, bitPos);
722
                        bitPos = ((Integer) val.get(0)).intValue();
723
                        dwgFile.setHeader("SURFTAB1", val.get(1));
724

    
725
                        val = DwgUtil.getBitShort(intData, bitPos);
726
                        bitPos = ((Integer) val.get(0)).intValue();
727
                        dwgFile.setHeader("SURFTAB2", val.get(1));
728

    
729
                        val = DwgUtil.getBitShort(intData, bitPos);
730
                        bitPos = ((Integer) val.get(0)).intValue();
731
                        dwgFile.setHeader("SPLINETYPE", val.get(1));
732

    
733
                        val = DwgUtil.getBitShort(intData, bitPos);
734
                        bitPos = ((Integer) val.get(0)).intValue();
735
                        dwgFile.setHeader("SHADEDGE", val.get(1));
736

    
737
                        val = DwgUtil.getBitShort(intData, bitPos);
738
                        bitPos = ((Integer) val.get(0)).intValue();
739
                        dwgFile.setHeader("SHADEDIF", val.get(1));
740

    
741
                        val = DwgUtil.getBitShort(intData, bitPos);
742
                        bitPos = ((Integer) val.get(0)).intValue();
743
                        dwgFile.setHeader("UNITMODE", val.get(1));
744

    
745
                        val = DwgUtil.getBitShort(intData, bitPos);
746
                        bitPos = ((Integer) val.get(0)).intValue();
747
                        dwgFile.setHeader("MAXACTVP", val.get(1));
748

    
749
                        val = DwgUtil.getBitShort(intData, bitPos);
750
                        bitPos = ((Integer) val.get(0)).intValue();
751
                        dwgFile.setHeader("ISOLINES", val.get(1));
752

    
753
                        val = DwgUtil.getBitShort(intData, bitPos);
754
                        bitPos = ((Integer) val.get(0)).intValue();
755
                        dwgFile.setHeader("CMLJUST", val.get(1));
756

    
757
                        val = DwgUtil.getBitShort(intData, bitPos);
758
                        bitPos = ((Integer) val.get(0)).intValue();
759
                        dwgFile.setHeader("TEXTQLTY", val.get(1));
760

    
761
                        val = DwgUtil.getBitDouble(intData, bitPos);
762
                        bitPos = ((Integer) val.get(0)).intValue();
763
                        dwgFile.setHeader("LTSCALE", val.get(1));
764

    
765
                        val = DwgUtil.getBitDouble(intData, bitPos);
766
                        bitPos = ((Integer) val.get(0)).intValue();
767
                        dwgFile.setHeader("TEXTSIZE", val.get(1));
768

    
769
                        val = DwgUtil.getBitDouble(intData, bitPos);
770
                        bitPos = ((Integer) val.get(0)).intValue();
771
                        dwgFile.setHeader("TRACEWID", val.get(1));
772

    
773
                        val = DwgUtil.getBitDouble(intData, bitPos);
774
                        bitPos = ((Integer) val.get(0)).intValue();
775
                        dwgFile.setHeader("SKETCHINC", val.get(1));
776

    
777
                        val = DwgUtil.getBitDouble(intData, bitPos);
778
                        bitPos = ((Integer) val.get(0)).intValue();
779
                        dwgFile.setHeader("FILLETRAD", val.get(1));
780

    
781
                        val = DwgUtil.getBitDouble(intData, bitPos);
782
                        bitPos = ((Integer) val.get(0)).intValue();
783
                        dwgFile.setHeader("THICKNESS", val.get(1));
784

    
785
                        val = DwgUtil.getBitDouble(intData, bitPos);
786
                        bitPos = ((Integer) val.get(0)).intValue();
787
                        dwgFile.setHeader("ANGBASE", val.get(1));
788

    
789
                        val = DwgUtil.getBitDouble(intData, bitPos);
790
                        bitPos = ((Integer) val.get(0)).intValue();
791
                        dwgFile.setHeader("PDSIZE", val.get(1));
792

    
793
                        val = DwgUtil.getBitDouble(intData, bitPos);
794
                        bitPos = ((Integer) val.get(0)).intValue();
795
                        dwgFile.setHeader("PLINEWID", val.get(1));
796

    
797
                        val = DwgUtil.getBitDouble(intData, bitPos);
798
                        bitPos = ((Integer) val.get(0)).intValue();
799
                        dwgFile.setHeader("USERR1", val.get(1));
800

    
801
                        val = DwgUtil.getBitDouble(intData, bitPos);
802
                        bitPos = ((Integer) val.get(0)).intValue();
803
                        dwgFile.setHeader("USERR2", val.get(1));
804

    
805
                        val = DwgUtil.getBitDouble(intData, bitPos);
806
                        bitPos = ((Integer) val.get(0)).intValue();
807
                        dwgFile.setHeader("USERR3", val.get(1));
808

    
809
                        val = DwgUtil.getBitDouble(intData, bitPos);
810
                        bitPos = ((Integer) val.get(0)).intValue();
811
                        dwgFile.setHeader("USERR4", val.get(1));
812

    
813
                        val = DwgUtil.getBitDouble(intData, bitPos);
814
                        bitPos = ((Integer) val.get(0)).intValue();
815
                        dwgFile.setHeader("USERR5", val.get(1));
816

    
817
                        val = DwgUtil.getBitDouble(intData, bitPos);
818
                        bitPos = ((Integer) val.get(0)).intValue();
819
                        dwgFile.setHeader("CHAMFERA", val.get(1));
820

    
821
                        val = DwgUtil.getBitDouble(intData, bitPos);
822
                        bitPos = ((Integer) val.get(0)).intValue();
823
                        dwgFile.setHeader("CHAMFERB", val.get(1));
824

    
825
                        val = DwgUtil.getBitDouble(intData, bitPos);
826
                        bitPos = ((Integer) val.get(0)).intValue();
827
                        dwgFile.setHeader("CHAMFERC", val.get(1));
828

    
829
                        val = DwgUtil.getBitDouble(intData, bitPos);
830
                        bitPos = ((Integer) val.get(0)).intValue();
831
                        dwgFile.setHeader("CHAMFERD", val.get(1));
832

    
833
                        val = DwgUtil.getBitDouble(intData, bitPos);
834
                        bitPos = ((Integer) val.get(0)).intValue();
835
                        dwgFile.setHeader("FACETRES", val.get(1));
836

    
837
                        val = DwgUtil.getBitDouble(intData, bitPos);
838
                        bitPos = ((Integer) val.get(0)).intValue();
839
                        dwgFile.setHeader("CMLSCALE", val.get(1));
840

    
841
                        val = DwgUtil.getBitDouble(intData, bitPos);
842
                        bitPos = ((Integer) val.get(0)).intValue();
843
                        dwgFile.setHeader("CELTSCALE", val.get(1));
844

    
845
                        val = DwgUtil.getTextString(intData, bitPos);
846
                        bitPos = ((Integer) val.get(0)).intValue();
847
                        dwgFile.setHeader("MENUNAME", val.get(1));
848

    
849
                        int[] tdcreate = new int[2];
850

    
851
                        val = DwgUtil.getBitLong(intData, bitPos);
852
                        bitPos = ((Integer) val.get(0)).intValue();
853
                        tdcreate[0] = ((Integer) val.get(1)).intValue();
854

    
855
                        val = DwgUtil.getBitLong(intData, bitPos);
856
                        bitPos = ((Integer) val.get(0)).intValue();
857
                        tdcreate[1] = ((Integer) val.get(1)).intValue();
858

    
859
                        dwgFile.setHeader("TDCREATE", tdcreate);
860

    
861
                        int[] tdupdate = new int[2];
862

    
863
                        val = DwgUtil.getBitLong(intData, bitPos);
864
                        bitPos = ((Integer) val.get(0)).intValue();
865
                        tdupdate[0] = ((Integer) val.get(1)).intValue();
866

    
867
                        val = DwgUtil.getBitLong(intData, bitPos);
868
                        bitPos = ((Integer) val.get(0)).intValue();
869
                        tdupdate[1] = ((Integer) val.get(1)).intValue();
870

    
871
                        dwgFile.setHeader("TDUPDATE", tdupdate);
872

    
873
                        val = DwgUtil.getBitLong(intData, bitPos);
874
                        bitPos = ((Integer) val.get(0)).intValue();
875
                        dwgFile.setHeader("UNKNOWN4", val.get(1));
876

    
877
                        val = DwgUtil.getBitLong(intData, bitPos);
878
                        bitPos = ((Integer) val.get(0)).intValue();
879
                        dwgFile.setHeader("UNKNOWN5", val.get(1));
880

    
881
                        val = DwgUtil.getBitLong(intData, bitPos);
882
                        bitPos = ((Integer) val.get(0)).intValue();
883
                        dwgFile.setHeader("UNKNOWN6", val.get(1));
884

    
885
                        int[] tdindwg = new int[2];
886

    
887
                        val = DwgUtil.getBitLong(intData, bitPos);
888
                        bitPos = ((Integer) val.get(0)).intValue();
889
                        tdindwg[0] = ((Integer) val.get(1)).intValue();
890

    
891
                        val = DwgUtil.getBitLong(intData, bitPos);
892
                        bitPos = ((Integer) val.get(0)).intValue();
893
                        tdindwg[1] = ((Integer) val.get(1)).intValue();
894

    
895
                        int[] tdusrtime = new int[2];
896

    
897
                        val = DwgUtil.getBitLong(intData, bitPos);
898
                        bitPos = ((Integer) val.get(0)).intValue();
899
                        tdusrtime[0] = ((Integer) val.get(1)).intValue();
900

    
901
                        val = DwgUtil.getBitLong(intData, bitPos);
902
                        bitPos = ((Integer) val.get(0)).intValue();
903
                        tdusrtime[1] = ((Integer) val.get(1)).intValue();
904

    
905
                        dwgFile.setHeader("TDUSRTIME", tdusrtime);
906

    
907
                        //FIXME: En versiones anteriores solo hab?a una variable
908
                        // "CECOLOR" de tipo entero, habr?a que comprobar donde se
909
                        // utiliza para, si es necesario, utilizar apropiadamente
910
                        // las nuevas.
911
                        val = DwgUtil.getCmColor(intData, bitPos, dwgFile.getDwgVersion());
912
                        bitPos = ((Integer) val.get(0)).intValue();
913
                        dwgFile.setHeader("CECOLOR", val.get(1));
914
                        dwgFile.setHeader("CECOLOR_RGBVALUE", val.get(2));
915
                        Object cecolorColorByte = val.get(3);
916
                        dwgFile.setHeader("CECOLOR_COLORBYTE", cecolorColorByte);
917
                        dwgFile.setHeader("CECOLOR_NAME", val.get(4));
918

    
919
                        dwgFile.getDwgVersion();
920

    
921
                        val = DwgUtil.getHandle(intData, bitPos);
922
                        bitPos = ((Integer) val.get(0)).intValue();
923
                        int intHandle = DwgUtil.handleToInt(val);
924
                        dwgFile.setHeader("HANDSEED", new Integer(intHandle));
925

    
926
                        val = DwgUtil.getHandle(intData, bitPos);
927
                        bitPos = ((Integer) val.get(0)).intValue();
928
                        intHandle = DwgUtil.handleToInt(val);
929
                        dwgFile.setHeader("CLAYER", new Integer(intHandle));
930

    
931
                        val = DwgUtil.getHandle(intData, bitPos);
932
                        bitPos = ((Integer) val.get(0)).intValue();
933
                        intHandle = DwgUtil.handleToInt(val);
934
                        dwgFile.setHeader("TEXSTYLE", new Integer(intHandle));
935

    
936
                        val = DwgUtil.getHandle(intData, bitPos);
937
                        bitPos = ((Integer) val.get(0)).intValue();
938
                        intHandle = DwgUtil.handleToInt(val);
939
                        dwgFile.setHeader("CELLTYPE", new Integer(intHandle));
940

    
941
                        val = DwgUtil.getHandle(intData, bitPos);
942
                        bitPos = ((Integer) val.get(0)).intValue();
943
                        intHandle = DwgUtil.handleToInt(val);
944
                        dwgFile.setHeader("DIMSTYLE", new Integer(intHandle));
945

    
946
                        val = DwgUtil.getHandle(intData, bitPos);
947
                        bitPos = ((Integer) val.get(0)).intValue();
948
                        intHandle = DwgUtil.handleToInt(val);
949
                        dwgFile.setHeader("CMLSTYLE", new Integer(intHandle));
950

    
951
                        // DWG 2000+
952
                        val = DwgUtil.getBitDouble(intData, bitPos);
953
                        bitPos = ((Integer) val.get(0)).intValue();
954
                        dwgFile.setHeader("PSVPSCALE", val.get(1));
955

    
956
                        double[] spaces1 = new double[3];
957

    
958
                        val = DwgUtil.getBitDouble(intData, bitPos);
959
                        bitPos = ((Integer) val.get(0)).intValue();
960
                        spaces1[0] = ((Double) val.get(1)).doubleValue();
961

    
962
                        val = DwgUtil.getBitDouble(intData, bitPos);
963
                        bitPos = ((Integer) val.get(0)).intValue();
964
                        spaces1[1] = ((Double) val.get(1)).doubleValue();
965

    
966
                        val = DwgUtil.getBitDouble(intData, bitPos);
967
                        bitPos = ((Integer) val.get(0)).intValue();
968
                        spaces1[2] = ((Double) val.get(1)).doubleValue();
969

    
970
                        dwgFile.setHeader("PSPACE_INSBASE", spaces1);
971

    
972
                        double[] spaces2 = new double[3];
973

    
974
                        val = DwgUtil.getBitDouble(intData, bitPos);
975
                        bitPos = ((Integer) val.get(0)).intValue();
976
                        spaces2[0] = ((Double) val.get(1)).doubleValue();
977

    
978
                        val = DwgUtil.getBitDouble(intData, bitPos);
979
                        bitPos = ((Integer) val.get(0)).intValue();
980
                        spaces2[1] = ((Double) val.get(1)).doubleValue();
981

    
982
                        val = DwgUtil.getBitDouble(intData, bitPos);
983
                        bitPos = ((Integer) val.get(0)).intValue();
984
                        spaces2[2] = ((Double) val.get(1)).doubleValue();
985

    
986
                        dwgFile.setHeader("PSPACE_EXTMIN", spaces2);
987

    
988
                        double[] spaces3 = new double[3];
989

    
990
                        val = DwgUtil.getBitDouble(intData, bitPos);
991
                        bitPos = ((Integer) val.get(0)).intValue();
992
                        spaces3[0] = ((Double) val.get(1)).doubleValue();
993

    
994
                        val = DwgUtil.getBitDouble(intData, bitPos);
995
                        bitPos = ((Integer) val.get(0)).intValue();
996
                        spaces3[1] = ((Double) val.get(1)).doubleValue();
997

    
998
                        val = DwgUtil.getBitDouble(intData, bitPos);
999
                        bitPos = ((Integer) val.get(0)).intValue();
1000
                        spaces3[2] = ((Double) val.get(1)).doubleValue();
1001
                        dwgFile.setHeader("PSPACE_EXTMAX", spaces2);
1002

    
1003
                        double[] spaces4 = new double[2];
1004
                        val = DwgUtil.getRawDouble(intData, bitPos);
1005
                        bitPos = ((Integer) val.get(0)).intValue();
1006
                        spaces4[0] = ((Double) val.get(1)).doubleValue();
1007

    
1008
                        val = DwgUtil.getRawDouble(intData, bitPos);
1009
                        bitPos = ((Integer) val.get(0)).intValue();
1010
                        spaces4[1] = ((Double) val.get(1)).doubleValue();
1011

    
1012
                        dwgFile.setHeader("PSPACE_LIMMIN", spaces4);
1013

    
1014
                        double[] spaces5 = new double[2];
1015
                        val = DwgUtil.getRawDouble(intData, bitPos);
1016
                        bitPos = ((Integer) val.get(0)).intValue();
1017
                        spaces5[0] = ((Double) val.get(1)).doubleValue();
1018

    
1019
                        val = DwgUtil.getRawDouble(intData, bitPos);
1020
                        bitPos = ((Integer) val.get(0)).intValue();
1021
                        spaces5[1] = ((Double) val.get(1)).doubleValue();
1022

    
1023
                        dwgFile.setHeader("PSPACE_LIMMAX", spaces5);
1024

    
1025
                        val = DwgUtil.getBitDouble(intData, bitPos);
1026
                        bitPos = ((Integer) val.get(0)).intValue();
1027
                        dwgFile.setHeader("PSPACE_ELEVATION", val.get(1));
1028

    
1029
                        double[] spaces6 = new double[6];
1030

    
1031
                        val = DwgUtil.getBitDouble(intData, bitPos);
1032
                        bitPos = ((Integer) val.get(0)).intValue();
1033
                        spaces6[0] = ((Double) val.get(1)).doubleValue();
1034

    
1035
                        val = DwgUtil.getBitDouble(intData, bitPos);
1036
                        bitPos = ((Integer) val.get(0)).intValue();
1037
                        spaces6[1] = ((Double) val.get(1)).doubleValue();
1038

    
1039
                        val = DwgUtil.getBitDouble(intData, bitPos);
1040
                        bitPos = ((Integer) val.get(0)).intValue();
1041
                        spaces6[2] = ((Double) val.get(1)).doubleValue();
1042

    
1043
                        dwgFile.setHeader("PSPACE_UCSORG", spaces6);
1044

    
1045
                        double[] spaces7 = new double[6];
1046
                        val = DwgUtil.getBitDouble(intData, bitPos);
1047
                        bitPos = ((Integer) val.get(0)).intValue();
1048
                        spaces7[0] = ((Double) val.get(1)).doubleValue();
1049

    
1050
                        val = DwgUtil.getBitDouble(intData, bitPos);
1051
                        bitPos = ((Integer) val.get(0)).intValue();
1052
                        spaces7[1] = ((Double) val.get(1)).doubleValue();
1053

    
1054
                        val = DwgUtil.getBitDouble(intData, bitPos);
1055
                        bitPos = ((Integer) val.get(0)).intValue();
1056
                        spaces7[2] = ((Double) val.get(1)).doubleValue();
1057

    
1058
                        dwgFile.setHeader("PSPACE_UCSXDIR", spaces7);
1059

    
1060
                        double[] spaces8 = new double[6];
1061
                        val = DwgUtil.getBitDouble(intData, bitPos);
1062
                        bitPos = ((Integer) val.get(0)).intValue();
1063
                        spaces8[0] = ((Double) val.get(1)).doubleValue();
1064

    
1065
                        val = DwgUtil.getBitDouble(intData, bitPos);
1066
                        bitPos = ((Integer) val.get(0)).intValue();
1067
                        spaces8[1] = ((Double) val.get(1)).doubleValue();
1068

    
1069
                        val = DwgUtil.getBitDouble(intData, bitPos);
1070
                        bitPos = ((Integer) val.get(0)).intValue();
1071
                        spaces8[2] = ((Double) val.get(1)).doubleValue();
1072

    
1073
                        dwgFile.setHeader("PSPACE_UCSYDIR", spaces8);
1074

    
1075
                        val = DwgUtil.getHandle(intData, bitPos);
1076
                        bitPos = ((Integer) val.get(0)).intValue();
1077
                        intHandle = DwgUtil.handleToInt(val);
1078
                        dwgFile.setHeader("PSPACE_UCSNAME", new Integer(intHandle));
1079

    
1080
                        // R2000+ Only
1081

    
1082
                        val = DwgUtil.getHandle(intData, bitPos);
1083
                        bitPos = ((Integer) val.get(0)).intValue();
1084
                        intHandle = DwgUtil.handleToInt(val);
1085
                        dwgFile.setHeader("PUCSBASE", new Integer(intHandle));
1086

    
1087
                        val = DwgUtil.getBitShort(intData, bitPos);
1088
                        bitPos = ((Integer) val.get(0)).intValue();
1089
                        dwgFile.setHeader("PUCSORTHOVIEW", val.get(1));
1090

    
1091
                        val = DwgUtil.getHandle(intData, bitPos);
1092
                        bitPos = ((Integer) val.get(0)).intValue();
1093
                        intHandle = DwgUtil.handleToInt(val);
1094
                        dwgFile.setHeader("PUCSORTHOREF", new Integer(intHandle));
1095

    
1096
                        double[] pucsorgtop = new double[3];
1097
                        val = DwgUtil.getBitDouble(intData, bitPos);
1098
                        bitPos = ((Integer) val.get(0)).intValue();
1099
                        pucsorgtop[0] = ((Double) val.get(1)).doubleValue();
1100
                        val = DwgUtil.getBitDouble(intData, bitPos);
1101
                        bitPos = ((Integer) val.get(0)).intValue();
1102
                        pucsorgtop[1] = ((Double) val.get(1)).doubleValue();
1103
                        val = DwgUtil.getBitDouble(intData, bitPos);
1104
                        bitPos = ((Integer) val.get(0)).intValue();
1105
                        pucsorgtop[2] = ((Double) val.get(1)).doubleValue();
1106
                        dwgFile.setHeader("PUCSORGTOP", pucsorgtop);
1107

    
1108
                        double[] pucsorgbottom = new double[3];
1109
                        val = DwgUtil.getBitDouble(intData, bitPos);
1110
                        bitPos = ((Integer) val.get(0)).intValue();
1111
                        pucsorgbottom[0] = ((Double) val.get(1)).doubleValue();
1112
                        val = DwgUtil.getBitDouble(intData, bitPos);
1113
                        bitPos = ((Integer) val.get(0)).intValue();
1114
                        pucsorgbottom[1] = ((Double) val.get(1)).doubleValue();
1115
                        val = DwgUtil.getBitDouble(intData, bitPos);
1116
                        bitPos = ((Integer) val.get(0)).intValue();
1117
                        pucsorgbottom[2] = ((Double) val.get(1)).doubleValue();
1118
                        dwgFile.setHeader("PUCSORGBOTTOM", pucsorgbottom);
1119

    
1120
                        double[] pucsorgleft = new double[3];
1121
                        val = DwgUtil.getBitDouble(intData, bitPos);
1122
                        bitPos = ((Integer) val.get(0)).intValue();
1123
                        pucsorgleft[0] = ((Double) val.get(1)).doubleValue();
1124
                        val = DwgUtil.getBitDouble(intData, bitPos);
1125
                        bitPos = ((Integer) val.get(0)).intValue();
1126
                        pucsorgleft[1] = ((Double) val.get(1)).doubleValue();
1127
                        val = DwgUtil.getBitDouble(intData, bitPos);
1128
                        bitPos = ((Integer) val.get(0)).intValue();
1129
                        pucsorgleft[2] = ((Double) val.get(1)).doubleValue();
1130
                        dwgFile.setHeader("PUCSORGLEFT", pucsorgleft);
1131

    
1132
                        double[] pucsorgright = new double[3];
1133
                        val = DwgUtil.getBitDouble(intData, bitPos);
1134
                        bitPos = ((Integer) val.get(0)).intValue();
1135
                        pucsorgright[0] = ((Double) val.get(1)).doubleValue();
1136
                        val = DwgUtil.getBitDouble(intData, bitPos);
1137
                        bitPos = ((Integer) val.get(0)).intValue();
1138
                        pucsorgright[1] = ((Double) val.get(1)).doubleValue();
1139
                        val = DwgUtil.getBitDouble(intData, bitPos);
1140
                        bitPos = ((Integer) val.get(0)).intValue();
1141
                        pucsorgright[2] = ((Double) val.get(1)).doubleValue();
1142
                        dwgFile.setHeader("PUCSORGRIGHT", pucsorgright);
1143

    
1144
                        double[] pucsorgfront = new double[3];
1145
                        val = DwgUtil.getBitDouble(intData, bitPos);
1146
                        bitPos = ((Integer) val.get(0)).intValue();
1147
                        pucsorgfront[0] = ((Double) val.get(1)).doubleValue();
1148
                        val = DwgUtil.getBitDouble(intData, bitPos);
1149
                        bitPos = ((Integer) val.get(0)).intValue();
1150
                        pucsorgfront[1] = ((Double) val.get(1)).doubleValue();
1151
                        val = DwgUtil.getBitDouble(intData, bitPos);
1152
                        bitPos = ((Integer) val.get(0)).intValue();
1153
                        pucsorgfront[2] = ((Double) val.get(1)).doubleValue();
1154
                        dwgFile.setHeader("PUCSORGFRONT", pucsorgfront);
1155

    
1156
                        double[] pucsorgback = new double[3];
1157
                        val = DwgUtil.getBitDouble(intData, bitPos);
1158
                        bitPos = ((Integer) val.get(0)).intValue();
1159
                        pucsorgback[0] = ((Double) val.get(1)).doubleValue();
1160
                        val = DwgUtil.getBitDouble(intData, bitPos);
1161
                        bitPos = ((Integer) val.get(0)).intValue();
1162
                        pucsorgback[1] = ((Double) val.get(1)).doubleValue();
1163
                        val = DwgUtil.getBitDouble(intData, bitPos);
1164
                        bitPos = ((Integer) val.get(0)).intValue();
1165
                        pucsorgback[2] = ((Double) val.get(1)).doubleValue();
1166
                        dwgFile.setHeader("PUCSORGBACK", pucsorgback);
1167

    
1168
                        // Common
1169

    
1170
                        double[] spaces9 = new double[6];
1171
                        val = DwgUtil.getBitDouble(intData, bitPos);
1172
                        bitPos = ((Integer) val.get(0)).intValue();
1173
                        spaces9[0] = ((Double) val.get(1)).doubleValue();
1174

    
1175
                        val = DwgUtil.getBitDouble(intData, bitPos);
1176
                        bitPos = ((Integer) val.get(0)).intValue();
1177
                        spaces9[1] = ((Double) val.get(1)).doubleValue();
1178

    
1179
                        val = DwgUtil.getBitDouble(intData, bitPos);
1180
                        bitPos = ((Integer) val.get(0)).intValue();
1181
                        spaces9[2] = ((Double) val.get(1)).doubleValue();
1182

    
1183
                        dwgFile.setHeader("MSPACE_INSBASE", spaces9);
1184

    
1185
                        double[] spaces10 = new double[6];
1186
                        val = DwgUtil.getBitDouble(intData, bitPos);
1187
                        bitPos = ((Integer) val.get(0)).intValue();
1188
                        spaces10[0] = ((Double) val.get(1)).doubleValue();
1189

    
1190
                        val = DwgUtil.getBitDouble(intData, bitPos);
1191
                        bitPos = ((Integer) val.get(0)).intValue();
1192
                        spaces10[1] = ((Double) val.get(1)).doubleValue();
1193

    
1194
                        val = DwgUtil.getBitDouble(intData, bitPos);
1195
                        bitPos = ((Integer) val.get(0)).intValue();
1196
                        spaces10[2] = ((Double) val.get(1)).doubleValue();
1197

    
1198
                        dwgFile.setHeader("MSPACE_EXTMIN", spaces10);
1199

    
1200
                        double[] spaces11 = new double[3];
1201
                        val = DwgUtil.getBitDouble(intData, bitPos);
1202
                        bitPos = ((Integer) val.get(0)).intValue();
1203
                        spaces11[0] = ((Double) val.get(1)).doubleValue();
1204

    
1205
                        val = DwgUtil.getBitDouble(intData, bitPos);
1206
                        bitPos = ((Integer) val.get(0)).intValue();
1207
                        spaces11[1] = ((Double) val.get(1)).doubleValue();
1208

    
1209
                        val = DwgUtil.getBitDouble(intData, bitPos);
1210
                        bitPos = ((Integer) val.get(0)).intValue();
1211
                        spaces11[2] = ((Double) val.get(1)).doubleValue();
1212

    
1213
                        dwgFile.setHeader("MSPACE_EXTMAX", spaces11);
1214

    
1215
                        double[] spaces12 = new double[2];
1216
                        val = DwgUtil.getRawDouble(intData, bitPos);
1217
                        bitPos = ((Integer) val.get(0)).intValue();
1218
                        spaces12[0] = ((Double) val.get(1)).doubleValue();
1219

    
1220
                        val = DwgUtil.getRawDouble(intData, bitPos);
1221
                        bitPos = ((Integer) val.get(0)).intValue();
1222
                        spaces12[1] = ((Double) val.get(1)).doubleValue();
1223

    
1224
                        dwgFile.setHeader("MSPACE_LIMMIN", spaces12);
1225

    
1226
                        double[] spaces13 = new double[2];
1227
                        val = DwgUtil.getRawDouble(intData, bitPos);
1228
                        bitPos = ((Integer) val.get(0)).intValue();
1229
                        spaces13[0] = ((Double) val.get(1)).doubleValue();
1230

    
1231
                        val = DwgUtil.getRawDouble(intData, bitPos);
1232
                        bitPos = ((Integer) val.get(0)).intValue();
1233
                        spaces13[1] = ((Double) val.get(1)).doubleValue();
1234

    
1235
                        dwgFile.setHeader("MSPACE_LIMMAX", spaces13);
1236

    
1237
                        val = DwgUtil.getBitDouble(intData, bitPos);
1238
                        bitPos = ((Integer) val.get(0)).intValue();
1239
                        dwgFile.setHeader("MSPACE_ELEVATION", (Double) val.get(1));
1240

    
1241
                        double[] spaces14 = new double[3];
1242
                        val = DwgUtil.getBitDouble(intData, bitPos);
1243
                        bitPos = ((Integer) val.get(0)).intValue();
1244
                        spaces14[0] = ((Double) val.get(1)).doubleValue();
1245

    
1246
                        val = DwgUtil.getBitDouble(intData, bitPos);
1247
                        bitPos = ((Integer) val.get(0)).intValue();
1248
                        spaces14[1] = ((Double) val.get(1)).doubleValue();
1249

    
1250
                        val = DwgUtil.getBitDouble(intData, bitPos);
1251
                        bitPos = ((Integer) val.get(0)).intValue();
1252
                        spaces14[2] = ((Double) val.get(1)).doubleValue();
1253

    
1254
                        dwgFile.setHeader("MSPACE_UCSORG", spaces14);
1255

    
1256
                        double[] spaces15 = new double[3];
1257
                        val = DwgUtil.getBitDouble(intData, bitPos);
1258
                        bitPos = ((Integer) val.get(0)).intValue();
1259
                        spaces15[0] = ((Double) val.get(1)).doubleValue();
1260

    
1261
                        val = DwgUtil.getBitDouble(intData, bitPos);
1262
                        bitPos = ((Integer) val.get(0)).intValue();
1263
                        spaces15[1] = ((Double) val.get(1)).doubleValue();
1264

    
1265
                        val = DwgUtil.getBitDouble(intData, bitPos);
1266
                        bitPos = ((Integer) val.get(0)).intValue();
1267
                        spaces15[2] = ((Double) val.get(1)).doubleValue();
1268

    
1269
                        dwgFile.setHeader("MSPACE_UCSXDIR", spaces15);
1270

    
1271
                        double[] spaces16 = new double[3];
1272
                        val = DwgUtil.getBitDouble(intData, bitPos);
1273
                        bitPos = ((Integer) val.get(0)).intValue();
1274
                        spaces16[0] = ((Double) val.get(1)).doubleValue();
1275

    
1276
                        val = DwgUtil.getBitDouble(intData, bitPos);
1277
                        bitPos = ((Integer) val.get(0)).intValue();
1278
                        spaces16[1] = ((Double) val.get(1)).doubleValue();
1279

    
1280
                        val = DwgUtil.getBitDouble(intData, bitPos);
1281
                        bitPos = ((Integer) val.get(0)).intValue();
1282
                        spaces16[2] = ((Double) val.get(1)).doubleValue();
1283

    
1284
                        dwgFile.setHeader("MSPACE_UCSYDIR", spaces16);
1285

    
1286
                        val = DwgUtil.getHandle(intData, bitPos);
1287
                        bitPos = ((Integer) val.get(0)).intValue();
1288
                        intHandle = DwgUtil.handleToInt(val);
1289
                        dwgFile.setHeader("MSPACE_UCSNAME", new Integer(intHandle));
1290

    
1291
                        val = DwgUtil.getHandle(intData, bitPos);
1292
                        bitPos = ((Integer) val.get(0)).intValue();
1293
                        intHandle = DwgUtil.handleToInt(val);
1294
                        dwgFile.setHeader("UCSBASE", new Integer(intHandle));
1295

    
1296
                        val = DwgUtil.getBitShort(intData, bitPos);
1297
                        bitPos = ((Integer) val.get(0)).intValue();
1298
                        dwgFile.setHeader("UCSORTHOVIEW", val.get(1));
1299

    
1300
                        val = DwgUtil.getHandle(intData, bitPos);
1301
                        bitPos = ((Integer) val.get(0)).intValue();
1302
                        intHandle = DwgUtil.handleToInt(val);
1303
                        dwgFile.setHeader("UCSORTHOREF", new Integer(intHandle));
1304

    
1305
                        double[] ucsorgtop = new double[3];
1306
                        val = DwgUtil.getBitDouble(intData, bitPos);
1307
                        bitPos = ((Integer) val.get(0)).intValue();
1308
                        ucsorgtop[0] = ((Double) val.get(1)).doubleValue();
1309
                        val = DwgUtil.getBitDouble(intData, bitPos);
1310
                        bitPos = ((Integer) val.get(0)).intValue();
1311
                        ucsorgtop[1] = ((Double) val.get(1)).doubleValue();
1312
                        val = DwgUtil.getBitDouble(intData, bitPos);
1313
                        bitPos = ((Integer) val.get(0)).intValue();
1314
                        ucsorgtop[2] = ((Double) val.get(1)).doubleValue();
1315
                        dwgFile.setHeader("UCSORGTOP", ucsorgtop);
1316

    
1317
                        double[] ucsorgbottom = new double[3];
1318
                        val = DwgUtil.getBitDouble(intData, bitPos);
1319
                        bitPos = ((Integer) val.get(0)).intValue();
1320
                        ucsorgbottom[0] = ((Double) val.get(1)).doubleValue();
1321
                        val = DwgUtil.getBitDouble(intData, bitPos);
1322
                        bitPos = ((Integer) val.get(0)).intValue();
1323
                        ucsorgbottom[1] = ((Double) val.get(1)).doubleValue();
1324
                        val = DwgUtil.getBitDouble(intData, bitPos);
1325
                        bitPos = ((Integer) val.get(0)).intValue();
1326
                        ucsorgbottom[2] = ((Double) val.get(1)).doubleValue();
1327
                        dwgFile.setHeader("UCSORGBOTTOM", ucsorgbottom);
1328

    
1329
                        double[] ucsorgleft = new double[3];
1330
                        val = DwgUtil.getBitDouble(intData, bitPos);
1331
                        bitPos = ((Integer) val.get(0)).intValue();
1332
                        ucsorgleft[0] = ((Double) val.get(1)).doubleValue();
1333
                        val = DwgUtil.getBitDouble(intData, bitPos);
1334
                        bitPos = ((Integer) val.get(0)).intValue();
1335
                        ucsorgleft[1] = ((Double) val.get(1)).doubleValue();
1336
                        val = DwgUtil.getBitDouble(intData, bitPos);
1337
                        bitPos = ((Integer) val.get(0)).intValue();
1338
                        ucsorgleft[2] = ((Double) val.get(1)).doubleValue();
1339
                        dwgFile.setHeader("UCSORGLEFT", ucsorgleft);
1340

    
1341
                        double[] ucsorgright = new double[3];
1342
                        val = DwgUtil.getBitDouble(intData, bitPos);
1343
                        bitPos = ((Integer) val.get(0)).intValue();
1344
                        ucsorgright[0] = ((Double) val.get(1)).doubleValue();
1345
                        val = DwgUtil.getBitDouble(intData, bitPos);
1346
                        bitPos = ((Integer) val.get(0)).intValue();
1347
                        ucsorgright[1] = ((Double) val.get(1)).doubleValue();
1348
                        val = DwgUtil.getBitDouble(intData, bitPos);
1349
                        bitPos = ((Integer) val.get(0)).intValue();
1350
                        ucsorgright[2] = ((Double) val.get(1)).doubleValue();
1351
                        dwgFile.setHeader("UCSORGRIGHT", ucsorgright);
1352

    
1353
                        double[] ucsorgfront = new double[3];
1354
                        val = DwgUtil.getBitDouble(intData, bitPos);
1355
                        bitPos = ((Integer) val.get(0)).intValue();
1356
                        ucsorgfront[0] = ((Double) val.get(1)).doubleValue();
1357
                        val = DwgUtil.getBitDouble(intData, bitPos);
1358
                        bitPos = ((Integer) val.get(0)).intValue();
1359
                        ucsorgfront[1] = ((Double) val.get(1)).doubleValue();
1360
                        val = DwgUtil.getBitDouble(intData, bitPos);
1361
                        bitPos = ((Integer) val.get(0)).intValue();
1362
                        ucsorgfront[2] = ((Double) val.get(1)).doubleValue();
1363
                        dwgFile.setHeader("UCSORGFRONT", ucsorgfront);
1364

    
1365
                        double[] ucsorgback = new double[3];
1366
                        val = DwgUtil.getBitDouble(intData, bitPos);
1367
                        bitPos = ((Integer) val.get(0)).intValue();
1368
                        ucsorgback[0] = ((Double) val.get(1)).doubleValue();
1369
                        val = DwgUtil.getBitDouble(intData, bitPos);
1370
                        bitPos = ((Integer) val.get(0)).intValue();
1371
                        ucsorgback[1] = ((Double) val.get(1)).doubleValue();
1372
                        val = DwgUtil.getBitDouble(intData, bitPos);
1373
                        bitPos = ((Integer) val.get(0)).intValue();
1374
                        ucsorgback[2] = ((Double) val.get(1)).doubleValue();
1375
                        dwgFile.setHeader("UCSORGBACK", ucsorgback);
1376

    
1377
                        val = DwgUtil.getTextString(intData, bitPos);
1378
                        bitPos = ((Integer) val.get(0)).intValue();
1379
                        dwgFile.setHeader("DIMPOST", val.get(1));
1380

    
1381
                        val = DwgUtil.getTextString(intData, bitPos);
1382
                        bitPos = ((Integer) val.get(0)).intValue();
1383
                        dwgFile.setHeader("DIMAPOST", val.get(1));
1384

    
1385
                        // Common
1386

    
1387
                        val = DwgUtil.getBitDouble(intData, bitPos);
1388
                        bitPos = ((Integer) val.get(0)).intValue();
1389
                        dwgFile.setHeader("DIMSCALE", val.get(1));
1390

    
1391
                        val = DwgUtil.getBitDouble(intData, bitPos);
1392
                        bitPos = ((Integer) val.get(0)).intValue();
1393
                        dwgFile.setHeader("DIMASZ", val.get(1));
1394

    
1395
                        val = DwgUtil.getBitDouble(intData, bitPos);
1396
                        bitPos = ((Integer) val.get(0)).intValue();
1397
                        dwgFile.setHeader("DIMEXO", val.get(1));
1398

    
1399
                        val = DwgUtil.getBitDouble(intData, bitPos);
1400
                        bitPos = ((Integer) val.get(0)).intValue();
1401
                        dwgFile.setHeader("DIMDLI", val.get(1));
1402

    
1403
                        val = DwgUtil.getBitDouble(intData, bitPos);
1404
                        bitPos = ((Integer) val.get(0)).intValue();
1405
                        dwgFile.setHeader("DIMEXE", val.get(1));
1406

    
1407
                        val = DwgUtil.getBitDouble(intData, bitPos);
1408
                        bitPos = ((Integer) val.get(0)).intValue();
1409
                        dwgFile.setHeader("DIMAND", val.get(1)); //FIXME: ?o es DIMRND?
1410

    
1411
                        val = DwgUtil.getBitDouble(intData, bitPos);
1412
                        bitPos = ((Integer) val.get(0)).intValue();
1413
                        dwgFile.setHeader("DIMDLE", val.get(1));
1414

    
1415
                        val = DwgUtil.getBitDouble(intData, bitPos);
1416
                        bitPos = ((Integer) val.get(0)).intValue();
1417
                        dwgFile.setHeader("DIMTP", val.get(1));
1418

    
1419
                        val = DwgUtil.getBitDouble(intData, bitPos);
1420
                        bitPos = ((Integer) val.get(0)).intValue();
1421
                        dwgFile.setHeader("DIMTM", val.get(1));
1422

    
1423
                        // DWG 2000 +
1424
                        val = DwgUtil.testBit(intData, bitPos);
1425
                        bitPos = ((Integer) val.get(0)).intValue();
1426
                        dwgFile.setHeader("DIMTOL", val.get(1));
1427

    
1428
                        val = DwgUtil.testBit(intData, bitPos);
1429
                        bitPos = ((Integer) val.get(0)).intValue();
1430
                        dwgFile.setHeader("DIMLIM", val.get(1));
1431

    
1432
                        val = DwgUtil.testBit(intData, bitPos);
1433
                        bitPos = ((Integer) val.get(0)).intValue();
1434
                        dwgFile.setHeader("DIMTIH", val.get(1));
1435

    
1436
                        val = DwgUtil.testBit(intData, bitPos);
1437
                        bitPos = ((Integer) val.get(0)).intValue();
1438
                        dwgFile.setHeader("DIMTOH", val.get(1));
1439

    
1440
                        val = DwgUtil.testBit(intData, bitPos);
1441
                        bitPos = ((Integer) val.get(0)).intValue();
1442
                        dwgFile.setHeader("DIMSE1", val.get(1));
1443

    
1444
                        val = DwgUtil.testBit(intData, bitPos);
1445
                        bitPos = ((Integer) val.get(0)).intValue();
1446
                        dwgFile.setHeader("DIMSE2", val.get(1));
1447

    
1448
                        val = DwgUtil.getBitShort(intData, bitPos);
1449
                        bitPos = ((Integer) val.get(0)).intValue();
1450
                        dwgFile.setHeader("DIMTAD", val.get(1));
1451

    
1452
                        val = DwgUtil.getBitShort(intData, bitPos);
1453
                        bitPos = ((Integer) val.get(0)).intValue();
1454
                        dwgFile.setHeader("DIMZIN", val.get(1));
1455

    
1456
                        val = DwgUtil.getBitShort(intData, bitPos);
1457
                        bitPos = ((Integer) val.get(0)).intValue();
1458
                        dwgFile.setHeader("DIMAZIN", val.get(1));
1459

    
1460
                        val = DwgUtil.getBitDouble(intData, bitPos);
1461
                        bitPos = ((Integer) val.get(0)).intValue();
1462
                        dwgFile.setHeader("DIMTXT", val.get(1));
1463

    
1464
                        val = DwgUtil.getBitDouble(intData, bitPos);
1465
                        bitPos = ((Integer) val.get(0)).intValue();
1466
                        dwgFile.setHeader("DIMCEN", val.get(1));
1467

    
1468
                        val = DwgUtil.getBitDouble(intData, bitPos);
1469
                        bitPos = ((Integer) val.get(0)).intValue();
1470
                        dwgFile.setHeader("DIMSZ", val.get(1));
1471

    
1472
                        val = DwgUtil.getBitDouble(intData, bitPos);
1473
                        bitPos = ((Integer) val.get(0)).intValue();
1474
                        dwgFile.setHeader("DIMALTF", val.get(1));
1475

    
1476
                        val = DwgUtil.getBitDouble(intData, bitPos);
1477
                        bitPos = ((Integer) val.get(0)).intValue();
1478
                        dwgFile.setHeader("DIMLFAC", val.get(1));
1479

    
1480
                        val = DwgUtil.getBitDouble(intData, bitPos);
1481
                        bitPos = ((Integer) val.get(0)).intValue();
1482
                        dwgFile.setHeader("DIMTVP", val.get(1));
1483

    
1484
                        val = DwgUtil.getBitDouble(intData, bitPos);
1485
                        bitPos = ((Integer) val.get(0)).intValue();
1486
                        dwgFile.setHeader("DIMTFAC", val.get(1));
1487

    
1488
                        val = DwgUtil.getBitDouble(intData, bitPos);
1489
                        bitPos = ((Integer) val.get(0)).intValue();
1490
                        dwgFile.setHeader("DIMGAP", val.get(1));
1491

    
1492
                        // DWG 2000+
1493

    
1494
                        val = DwgUtil.getBitDouble(intData, bitPos);
1495
                        bitPos = ((Integer) val.get(0)).intValue();
1496
                        dwgFile.setHeader("DIMALTRND", val.get(1));
1497

    
1498
                        val = DwgUtil.testBit(intData, bitPos);
1499
                        bitPos = ((Integer) val.get(0)).intValue();
1500
                        dwgFile.setHeader("DIMALT", val.get(1));
1501

    
1502
                        val = DwgUtil.getBitShort(intData, bitPos);
1503
                        bitPos = ((Integer) val.get(0)).intValue();
1504
                        dwgFile.setHeader("DIMALTD", val.get(1));
1505

    
1506
                        val = DwgUtil.testBit(intData, bitPos);
1507
                        bitPos = ((Integer) val.get(0)).intValue();
1508
                        dwgFile.setHeader("DIMTOFL", val.get(1));
1509

    
1510
                        val = DwgUtil.testBit(intData, bitPos);
1511
                        bitPos = ((Integer) val.get(0)).intValue();
1512
                        dwgFile.setHeader("DIMSAH", val.get(1));
1513

    
1514
                        val = DwgUtil.testBit(intData, bitPos);
1515
                        bitPos = ((Integer) val.get(0)).intValue();
1516
                        dwgFile.setHeader("DIMTIX", val.get(1));
1517

    
1518
                        val = DwgUtil.testBit(intData, bitPos);
1519
                        bitPos = ((Integer) val.get(0)).intValue();
1520
                        dwgFile.setHeader("DIMSOXD", val.get(1));
1521

    
1522
                        // common
1523

    
1524
                        //FIXME: En versiones anteriores solo hab?a una variable
1525
                        // "DIMCLRD" de tipo entero, habr?a que comprobar donde se
1526
                        // utiliza para, si es necesario, utilizar apropiadamente
1527
                        // las nuevas. Lo mismo con "DIMCLRE" y "DIMCLRT".
1528

    
1529
                        val = DwgUtil.getCmColor(intData, bitPos, dwgFile.getDwgVersion());
1530
                        bitPos = ((Integer) val.get(0)).intValue();
1531
                        dwgFile.setHeader("DIMCLRD", val.get(1));
1532
                        dwgFile.setHeader("DIMCLRD_RGBVALUE", val.get(2));
1533
                        Object dimclrdColorByte = val.get(3);
1534
                        dwgFile.setHeader("DIMCLRD_COLORBYTE", dimclrdColorByte);
1535
                        dwgFile.setHeader("DIMCLRD_NAME", val.get(4));
1536

    
1537
                        val = DwgUtil.getCmColor(intData, bitPos, dwgFile.getDwgVersion());
1538
                        bitPos = ((Integer) val.get(0)).intValue();
1539
                        dwgFile.setHeader("DIMCLRE", val.get(1));
1540
                        dwgFile.setHeader("DIMCLRE_RGBVALUE", val.get(2));
1541
                        Object dimclreColorByte = val.get(3);
1542
                        dwgFile.setHeader("DIMCLRE_COLORBYTE", dimclreColorByte);
1543
                        dwgFile.setHeader("DIMCLRE_NAME", val.get(4));
1544

    
1545
                        val = DwgUtil.getCmColor(intData, bitPos, dwgFile.getDwgVersion());
1546
                        bitPos = ((Integer) val.get(0)).intValue();
1547
                        dwgFile.setHeader("DIMCLRT", val.get(1));
1548
                        dwgFile.setHeader("DIMCLRT_RGBVALUE", val.get(2));
1549
                        Object dimclrtColorByte = val.get(3);
1550
                        dwgFile.setHeader("DIMCLRT_COLORBYTE", dimclrtColorByte);
1551

    
1552
                        dwgFile.setHeader("DIMCLRT_NAME", val.get(4));
1553

    
1554
                        // dwg2000 +
1555

    
1556
                        val = DwgUtil.getBitShort(intData, bitPos);
1557
                        bitPos = ((Integer) val.get(0)).intValue();
1558
                        dwgFile.setHeader("DIMADEC", val.get(1));
1559

    
1560
                        val = DwgUtil.getBitShort(intData, bitPos);
1561
                        bitPos = ((Integer) val.get(0)).intValue();
1562
                        dwgFile.setHeader("DIMDEC", val.get(1));
1563

    
1564
                        val = DwgUtil.getBitShort(intData, bitPos);
1565
                        bitPos = ((Integer) val.get(0)).intValue();
1566
                        dwgFile.setHeader("DIMTDEC", val.get(1));
1567

    
1568
                        val = DwgUtil.getBitShort(intData, bitPos);
1569
                        bitPos = ((Integer) val.get(0)).intValue();
1570
                        dwgFile.setHeader("DIMALTU", val.get(1));
1571

    
1572
                        val = DwgUtil.getBitShort(intData, bitPos);
1573
                        bitPos = ((Integer) val.get(0)).intValue();
1574
                        dwgFile.setHeader("DIMALTTD", val.get(1));
1575

    
1576
                        val = DwgUtil.getBitShort(intData, bitPos);
1577
                        bitPos = ((Integer) val.get(0)).intValue();
1578
                        dwgFile.setHeader("DIMAUNIT", val.get(1));
1579

    
1580
                        val = DwgUtil.getBitShort(intData, bitPos);
1581
                        bitPos = ((Integer) val.get(0)).intValue();
1582
                        dwgFile.setHeader("DIMFRAC", val.get(1));
1583

    
1584
                        val = DwgUtil.getBitShort(intData, bitPos);
1585
                        bitPos = ((Integer) val.get(0)).intValue();
1586
                        dwgFile.setHeader("DIMLUNIT", val.get(1));
1587

    
1588
                        val = DwgUtil.getBitShort(intData, bitPos);
1589
                        bitPos = ((Integer) val.get(0)).intValue();
1590
                        dwgFile.setHeader("DIMDSEP", val.get(1));
1591

    
1592
                        val = DwgUtil.getBitShort(intData, bitPos);
1593
                        bitPos = ((Integer) val.get(0)).intValue();
1594
                        dwgFile.setHeader("DIMTMOVE", val.get(1));
1595

    
1596
                        val = DwgUtil.getBitShort(intData, bitPos);
1597
                        bitPos = ((Integer) val.get(0)).intValue();
1598
                        dwgFile.setHeader("DIMJUST", val.get(1));
1599

    
1600
                        val = DwgUtil.testBit(intData, bitPos);
1601
                        bitPos = ((Integer) val.get(0)).intValue();
1602
                        dwgFile.setHeader("DIMSD1", val.get(1));
1603

    
1604
                        val = DwgUtil.testBit(intData, bitPos);
1605
                        bitPos = ((Integer) val.get(0)).intValue();
1606
                        dwgFile.setHeader("DIMSD2", val.get(1));
1607

    
1608
                        val = DwgUtil.getBitShort(intData, bitPos);
1609
                        bitPos = ((Integer) val.get(0)).intValue();
1610
                        dwgFile.setHeader("DIMTOLJ", val.get(1));
1611

    
1612
                        val = DwgUtil.getBitShort(intData, bitPos);
1613
                        bitPos = ((Integer) val.get(0)).intValue();
1614
                        dwgFile.setHeader("DIMTZIN", val.get(1));
1615

    
1616
                        val = DwgUtil.getBitShort(intData, bitPos);
1617
                        bitPos = ((Integer) val.get(0)).intValue();
1618
                        dwgFile.setHeader("DIMALTZ", val.get(1));
1619

    
1620
                        val = DwgUtil.getBitShort(intData, bitPos);
1621
                        bitPos = ((Integer) val.get(0)).intValue();
1622
                        dwgFile.setHeader("DIMALTTZ", val.get(1));
1623

    
1624
                        val = DwgUtil.testBit(intData, bitPos);
1625
                        bitPos = ((Integer) val.get(0)).intValue();
1626
                        dwgFile.setHeader("DIMUPT", val.get(1));
1627

    
1628
                        val = DwgUtil.getBitShort(intData, bitPos);
1629
                        bitPos = ((Integer) val.get(0)).intValue();
1630
                        dwgFile.setHeader("DIMFIT", val.get(1));
1631

    
1632
                        val = DwgUtil.getHandle(intData, bitPos);
1633
                        bitPos = ((Integer) val.get(0)).intValue();
1634
                        intHandle = DwgUtil.handleToInt(val);
1635
                        dwgFile.setHeader("DIMTXTSTY", new Integer(intHandle));
1636

    
1637
                        val = DwgUtil.getHandle(intData, bitPos);
1638
                        bitPos = ((Integer) val.get(0)).intValue();
1639
                        intHandle = DwgUtil.handleToInt(val);
1640
                        dwgFile.setHeader("DIMLDRBLK", new Integer(intHandle));
1641

    
1642
                        val = DwgUtil.getHandle(intData, bitPos);
1643
                        bitPos = ((Integer) val.get(0)).intValue();
1644
                        intHandle = DwgUtil.handleToInt(val);
1645
                        dwgFile.setHeader("DIMBLK", new Integer(intHandle));
1646

    
1647
                        val = DwgUtil.getHandle(intData, bitPos);
1648
                        bitPos = ((Integer) val.get(0)).intValue();
1649
                        intHandle = DwgUtil.handleToInt(val);
1650
                        dwgFile.setHeader("DIMBLK1", new Integer(intHandle));
1651

    
1652
                        val = DwgUtil.getHandle(intData, bitPos);
1653
                        bitPos = ((Integer) val.get(0)).intValue();
1654
                        intHandle = DwgUtil.handleToInt(val);
1655
                        dwgFile.setHeader("DIMBLK2", new Integer(intHandle));
1656

    
1657
                        val = DwgUtil.getBitShort(intData, bitPos);
1658
                        bitPos = ((Integer) val.get(0)).intValue();
1659
                        dwgFile.setHeader("DIMLWD", val.get(1));
1660

    
1661
                        val = DwgUtil.getBitShort(intData, bitPos);
1662
                        bitPos = ((Integer) val.get(0)).intValue();
1663
                        dwgFile.setHeader("DIMLWE", val.get(1));
1664

    
1665
                        // Common
1666

    
1667
                        val = DwgUtil.getHandle(intData, bitPos);
1668
                        bitPos = ((Integer) val.get(0)).intValue();
1669
                        intHandle = DwgUtil.handleToInt(val);
1670
                        dwgFile.setHeader("BLOCK_CONTROL_OBJECT", new Integer(intHandle));
1671

    
1672
                        val = DwgUtil.getHandle(intData, bitPos);
1673
                        bitPos = ((Integer) val.get(0)).intValue();
1674
                        intHandle = DwgUtil.handleToInt(val);
1675
                        dwgFile.setHeader("LAYER_CONTROL_OBJECT", new Integer(intHandle));
1676

    
1677
                        val = DwgUtil.getHandle(intData, bitPos);
1678
                        bitPos = ((Integer) val.get(0)).intValue();
1679
                        intHandle = DwgUtil.handleToInt(val);
1680
                        dwgFile.setHeader("STYLE_CONTROL_OBJECT", new Integer(intHandle));
1681

    
1682
                        val = DwgUtil.getHandle(intData, bitPos);
1683
                        bitPos = ((Integer) val.get(0)).intValue();
1684
                        intHandle = DwgUtil.handleToInt(val);
1685
                        dwgFile.setHeader("LINETYPE_CONTROL_OBJECT", new Integer(intHandle));
1686

    
1687
                        val = DwgUtil.getHandle(intData, bitPos);
1688
                        bitPos = ((Integer) val.get(0)).intValue();
1689
                        intHandle = DwgUtil.handleToInt(val);
1690
                        dwgFile.setHeader("VIEW_CONTROL_OBJECT", new Integer(intHandle));
1691

    
1692
                        val = DwgUtil.getHandle(intData, bitPos);
1693
                        bitPos = ((Integer) val.get(0)).intValue();
1694
                        intHandle = DwgUtil.handleToInt(val);
1695
                        dwgFile.setHeader("UCS_CONTROL_OBJECT", new Integer(intHandle));
1696

    
1697
                        val = DwgUtil.getHandle(intData, bitPos);
1698
                        bitPos = ((Integer) val.get(0)).intValue();
1699
                        intHandle = DwgUtil.handleToInt(val);
1700
                        dwgFile.setHeader("VPORT_CONTROL_OBJECT", new Integer(intHandle));
1701

    
1702
                        val = DwgUtil.getHandle(intData, bitPos);
1703
                        bitPos = ((Integer) val.get(0)).intValue();
1704
                        intHandle = DwgUtil.handleToInt(val);
1705
                        dwgFile.setHeader("APPID_CONTROL_OBJECT", new Integer(intHandle));
1706

    
1707
                        val = DwgUtil.getHandle(intData, bitPos);
1708
                        bitPos = ((Integer) val.get(0)).intValue();
1709
                        intHandle = DwgUtil.handleToInt(val);
1710
                        dwgFile.setHeader("DIMSTYLE_CONTROL_OBJECT", new Integer(intHandle));
1711

    
1712
                        val = DwgUtil.getHandle(intData, bitPos);
1713
                        bitPos = ((Integer) val.get(0)).intValue();
1714
                        intHandle = DwgUtil.handleToInt(val);
1715
                        dwgFile.setHeader("ACAD_GROUP_DICTIONARY", new Integer(intHandle));
1716

    
1717
                        val = DwgUtil.getHandle(intData, bitPos);
1718
                        bitPos = ((Integer) val.get(0)).intValue();
1719
                        intHandle = DwgUtil.handleToInt(val);
1720
                        dwgFile.setHeader("ACAD_MLINE_DICTIONARY", new Integer(intHandle));
1721

    
1722
                        val = DwgUtil.getHandle(intData, bitPos);
1723
                        bitPos = ((Integer) val.get(0)).intValue();
1724
                        intHandle = DwgUtil.handleToInt(val);
1725
                        dwgFile.setHeader("NAMED_OBJECT_DICTIONARY", new Integer(intHandle));
1726
                        // DWG 2000+
1727

    
1728
                        // unknown bitshort
1729
                        val = DwgUtil.getBitShort(intData, bitPos);
1730
                        bitPos = ((Integer) val.get(0)).intValue();
1731

    
1732
                        // unknown bitshort
1733
                        val = DwgUtil.getBitShort(intData, bitPos);
1734
                        bitPos = ((Integer) val.get(0)).intValue();
1735

    
1736
                        val = DwgUtil.getTextString(intData, bitPos);
1737
                        bitPos = ((Integer) val.get(0)).intValue();
1738
                        dwgFile.setHeader("HYPERLINKBASE", val.get(1));
1739

    
1740
                        val = DwgUtil.getTextString(intData, bitPos);
1741
                        bitPos = ((Integer) val.get(0)).intValue();
1742
                        dwgFile.setHeader("STYLESHEET", val.get(1));
1743

    
1744
                        val = DwgUtil.getHandle(intData, bitPos);
1745
                        bitPos = ((Integer) val.get(0)).intValue();
1746
                        intHandle = DwgUtil.handleToInt(val);
1747
                        dwgFile.setHeader("LAYOUT_DICTIONARY", new Integer(intHandle));
1748

    
1749
                        val = DwgUtil.getHandle(intData, bitPos);
1750
                        bitPos = ((Integer) val.get(0)).intValue();
1751
                        intHandle = DwgUtil.handleToInt(val);
1752
                        dwgFile.setHeader("PLOT_SETTINGS_DICTIONARY",
1753
                                        new Integer(intHandle));
1754

    
1755
                        val = DwgUtil.getHandle(intData, bitPos);
1756
                        bitPos = ((Integer) val.get(0)).intValue();
1757
                        intHandle = DwgUtil.handleToInt(val);
1758
                        dwgFile.setHeader("PLOT_STYLES_DICTIONARY", new Integer(intHandle));
1759

    
1760
                        // DWG 2004+
1761
                        val = DwgUtil.getHandle(intData, bitPos);
1762
                        bitPos = ((Integer) val.get(0)).intValue();
1763
                        intHandle = DwgUtil.handleToInt(val);
1764
                        dwgFile.setHeader("MATERIALS_DICTIONARY", new Integer(intHandle));
1765

    
1766
                        val = DwgUtil.getHandle(intData, bitPos);
1767
                        bitPos = ((Integer) val.get(0)).intValue();
1768
                        intHandle = DwgUtil.handleToInt(val);
1769
                        dwgFile.setHeader("COLORS_DICTIONARY", new Integer(intHandle));
1770

    
1771
                        // DWG 2000 +
1772

    
1773
                        /*
1774
                         * Flags:
1775
                         * CELWEIGHT        Flags & 0x001F
1776
                         * ENDCAPS                Flags & 0x0060
1777
                         * JOINSTYLE        Flags & 0x0180
1778
                         * LWDISPLAY        !(Flags & 0x0200)
1779
                         * XEDIT                !(Flags & 0x0400)
1780
                         * EXTNAMES                Flags & 0x0800
1781
                         * PSTYLEMODE        Flags & 0x2000
1782
                         * OLESTARTUP        Flags & 0x4000
1783
                         */
1784
                        val = DwgUtil.getBitLong(intData, bitPos);
1785
                        bitPos = ((Integer) val.get(0)).intValue();
1786
                        dwgFile.setHeader("FLAGS", val.get(1));
1787

    
1788
                        val = DwgUtil.getBitShort(intData, bitPos);
1789
                        bitPos = ((Integer) val.get(0)).intValue();
1790
                        dwgFile.setHeader("INSUNITS", val.get(1));
1791

    
1792
                        val = DwgUtil.getBitShort(intData, bitPos);
1793
                        bitPos = ((Integer) val.get(0)).intValue();
1794
                        dwgFile.setHeader("CEPSNTYPE", val.get(1));
1795

    
1796
                        if (((Integer) val.get(1)).intValue() == 3) {
1797
                                val = DwgUtil.getHandle(intData, bitPos);
1798
                                bitPos = ((Integer) val.get(0)).intValue();
1799
                                intHandle = DwgUtil.handleToInt(val);
1800
                                dwgFile.setHeader("CPSNID", new Integer(intHandle));
1801
                        }
1802

    
1803
                        val = DwgUtil.getTextString(intData, bitPos);
1804
                        bitPos = ((Integer) val.get(0)).intValue();
1805
                        dwgFile.setHeader("FINGERPRINTGUID", val.get(1));
1806

    
1807
                        val = DwgUtil.getTextString(intData, bitPos);
1808
                        bitPos = ((Integer) val.get(0)).intValue();
1809
                        dwgFile.setHeader("VERSIONGUID", val.get(1));
1810

    
1811
                        // DWG 2004+
1812

    
1813
                        val = DwgUtil.getRawChar(intData, bitPos);
1814
                        bitPos = ((Integer) val.get(0)).intValue();
1815
                        dwgFile.setHeader("SORTENTS", val.get(1));
1816

    
1817
                        val = DwgUtil.getRawChar(intData, bitPos);
1818
                        bitPos = ((Integer) val.get(0)).intValue();
1819
                        dwgFile.setHeader("INDEXCTL", val.get(1));
1820

    
1821
                        val = DwgUtil.getRawChar(intData, bitPos);
1822
                        bitPos = ((Integer) val.get(0)).intValue();
1823
                        dwgFile.setHeader("HIDETEXT", val.get(1));
1824

    
1825
                        val = DwgUtil.getRawChar(intData, bitPos);
1826
                        bitPos = ((Integer) val.get(0)).intValue();
1827
                        dwgFile.setHeader("XCLIPFRAME", val.get(1));
1828

    
1829
                        val = DwgUtil.getRawChar(intData, bitPos);
1830
                        bitPos = ((Integer) val.get(0)).intValue();
1831
                        dwgFile.setHeader("DIMASSOC", val.get(1));
1832

    
1833
                        val = DwgUtil.getRawChar(intData, bitPos);
1834
                        bitPos = ((Integer) val.get(0)).intValue();
1835
                        dwgFile.setHeader("HALOGAP", val.get(1));
1836

    
1837
                        val = DwgUtil.getBitShort(intData, bitPos);
1838
                        bitPos = ((Integer) val.get(0)).intValue();
1839
                        dwgFile.setHeader("OBSCUREDCOLOR", val.get(1));
1840

    
1841
                        val = DwgUtil.getBitShort(intData, bitPos);
1842
                        bitPos = ((Integer) val.get(0)).intValue();
1843
                        dwgFile.setHeader("INTERSECTION_COLOR", val.get(1));
1844

    
1845
                        val = DwgUtil.getRawChar(intData, bitPos);
1846
                        bitPos = ((Integer) val.get(0)).intValue();
1847
                        dwgFile.setHeader("OBSCUREDLTYPE", val.get(1));
1848

    
1849
                        val = DwgUtil.getRawChar(intData, bitPos);
1850
                        bitPos = ((Integer) val.get(0)).intValue();
1851
                        dwgFile.setHeader("INTERSECTION_DISPLAY", val.get(1));
1852

    
1853
                        val = DwgUtil.getTextString(intData, bitPos);
1854
                        bitPos = ((Integer) val.get(0)).intValue();
1855
                        dwgFile.setHeader("PROJECTNAME", val.get(1));
1856

    
1857
                        // Common
1858

    
1859
                        val = DwgUtil.getHandle(intData, bitPos);
1860
                        bitPos = ((Integer) val.get(0)).intValue();
1861
                        intHandle = DwgUtil.handleToInt(val);
1862
                        dwgFile.setHeader("PAPER_BLOCK_RECORD", new Integer(intHandle));
1863

    
1864
                        val = DwgUtil.getHandle(intData, bitPos);
1865
                        bitPos = ((Integer) val.get(0)).intValue();
1866
                        intHandle = DwgUtil.handleToInt(val);
1867
                        dwgFile.setHeader("MODEL_BLOCK_RECORD", new Integer(intHandle));
1868

    
1869
                        val = DwgUtil.getHandle(intData, bitPos);
1870
                        bitPos = ((Integer) val.get(0)).intValue();
1871
                        intHandle = DwgUtil.handleToInt(val);
1872
                        dwgFile.setHeader("LTYPE_BYLAYER", new Integer(intHandle));
1873

    
1874
                        val = DwgUtil.getHandle(intData, bitPos);
1875
                        bitPos = ((Integer) val.get(0)).intValue();
1876
                        intHandle = DwgUtil.handleToInt(val);
1877
                        dwgFile.setHeader("LTYPE_BYBLOCK", new Integer(intHandle));
1878

    
1879
                        val = DwgUtil.getHandle(intData, bitPos);
1880
                        bitPos = ((Integer) val.get(0)).intValue();
1881
                        intHandle = DwgUtil.handleToInt(val);
1882
                        dwgFile.setHeader("LTYPE_CONTINUOUS", new Integer(intHandle));
1883

    
1884
                } catch (Exception e) {
1885
                        logger.error(e);
1886
                }
1887

    
1888
        }
1889

    
1890
        /**
1891
         * decrypts the encrypted data
1892
         *
1893
         * @param encrypted
1894
         *            encrypted data
1895
         * @param offset
1896
         *            current position in file
1897
         * @return vector with the decrypted data
1898
         */
1899
        private int[] decryptSectionHeader(byte[] encrypted, int offset) {
1900
                int secMask = 0x4164536b ^ offset;
1901
                int[] decrypted = new int[8];
1902
                ByteBuffer Hdr = ByteBuffer.allocate(32);
1903
                Hdr.position(0);
1904
                Hdr.put(encrypted);
1905
                Hdr.order(ByteOrder.LITTLE_ENDIAN);
1906
                Hdr.position(0);
1907

    
1908
                for (int i = 0; i < 8; i++) {
1909
                        int aux = Hdr.getInt();
1910
                        aux = aux ^ secMask;
1911
                        decrypted[i] = aux;
1912
                }
1913
                return decrypted;
1914
        }
1915

    
1916
        /**
1917
         * Find all subsections of a section named "name" in the section's array sorted by startOffset
1918
         *
1919
         * @param name
1920
         *            String name of the section to find
1921
         *
1922
         * @return vector with sections named 2name"
1923
         */
1924
        private Section[] findSections(String name) {
1925

    
1926
                Comparator cmp = new Comparator(){
1927

    
1928
                        public int compare(Object arg0, Object arg1) {
1929
                                if (((Section)arg0).getStartOffset() > ((Section)arg1).getStartOffset()) {
1930
                                        return 1;
1931
                }
1932
                                return -1;
1933
                        }
1934

    
1935
                };
1936
                TreeSet foundSections = new TreeSet(cmp);
1937

    
1938
                for (int i = 0; i < sectionAmount; i++) {
1939
                        if (sections[i].getName() != null
1940
                                        && sections[i].getName().contains(name)) {
1941
                                foundSections.add(sections[i]);
1942
                        }
1943
                        if (i == sectionAmount)
1944
                                logger.warn("No se han encontrado secciones llamadas \"" + name + "\"");
1945
                }
1946
                return (Section[]) foundSections.toArray(new Section[0]);
1947
        }
1948

    
1949

    
1950
        /**
1951
         * Contains the defined classes for drawing
1952
         *
1953
         * @param bb
1954
         *            ByteBuffer containing the opened DWG file
1955
         */
1956
        private void readDwgR2004Classes(ByteBuffer bb) {
1957

    
1958
                ByteBuffer decompressedBB = readSection(bb, "AcDb:Classes");
1959

    
1960
                byte[] sentinel = new byte[16];
1961
                decompressedBB.order(ByteOrder.nativeOrder());
1962
                decompressedBB.position(0);
1963
                decompressedBB.get(sentinel); // we get the sentinel that ALWAYS
1964
                // appears before the data
1965

    
1966
                if ((sentinel[0] & 0XFF) != 0x8d)
1967
                        logger.warn(" sentinel[0] != 0x8d");
1968
                if ((sentinel[1] & 0XFF) != 0xa1)
1969
                        logger.warn("sentinel[1] != 0xa1");
1970
                if ((sentinel[2] & 0XFF) != 0xc4)
1971
                        logger.warn("sentinel[2] != 0xc4");
1972
                if ((sentinel[3] & 0XFF) != 0xb8)
1973
                        logger.warn("sentinel[3] != 0xb8");
1974
                if ((sentinel[4] & 0XFF) != 0xc4)
1975
                        logger.warn("sentinel[4] != 0xc4");
1976
                if ((sentinel[5] & 0XFF) != 0xa9)
1977
                        logger.warn("sentinel[5] != 0xa9");
1978
                if ((sentinel[6] & 0XFF) != 0xf8)
1979
                        logger.warn("sentinel[6] != 0xf8");
1980
                if ((sentinel[7] & 0XFF) != 0xc5)
1981
                        logger.warn("sentinel[7] != 0xc5");
1982
                if ((sentinel[8] & 0XFF) != 0xc0)
1983
                        logger.warn("sentinel[8] != 0xc0");
1984
                if ((sentinel[9] & 0XFF) != 0xdc)
1985
                        logger.warn("sentinel[9] != 0xdc");
1986
                if ((sentinel[10] & 0XFF) != 0xf4)
1987
                        logger.warn("sentinel[10] != 0xf4");
1988
                if ((sentinel[11] & 0XFF) != 0x5f)
1989
                        logger.warn("sentinel[11] != 0x5f");
1990
                if ((sentinel[12] & 0XFF) != 0xe7)
1991
                        logger.warn("sentinel[12] != 0xe7");
1992
                if ((sentinel[13] & 0XFF) != 0xcf)
1993
                        logger.warn("sentinel[13] != 0xcf");
1994
                if ((sentinel[14] & 0XFF) != 0xb6)
1995
                        logger.warn("sentinel[14] != 0xb6");
1996
                if ((sentinel[15] & 0XFF) != 0x8a)
1997
                        logger.warn("sentinel[15] != 0x8a");
1998

    
1999
                // we start working with data that comes after the beginning sentinel
2000
                decompressedBB.order(ByteOrder.LITTLE_ENDIAN);
2001
                int size = decompressedBB.getInt();
2002

    
2003
                decompressedBB.order(ByteOrder.nativeOrder());
2004
                byte[] data = new byte[size];
2005
                decompressedBB.get(data);
2006

    
2007
                int[] intData = DwgUtil.toIntArray(data);
2008

    
2009
                bb.order(ByteOrder.LITTLE_ENDIAN);
2010
                short crc = decompressedBB.getShort(); // CRC
2011

    
2012
                List val = null;
2013
                int bitPos = 0;
2014

    
2015
                val = DwgUtil.getBitShort(intData, bitPos);
2016
                bitPos = ((Integer) val.get(0)).intValue();
2017
                int MaxclassNum = ((Integer) val.get(1)).intValue();
2018

    
2019
                val = DwgUtil.getRawChar(intData, bitPos); // 0x00
2020
                if (((Integer) val.get(1)).intValue() != 0x00) {
2021
                        logger.warn("Classes Section RC1 != 0x00");
2022
                }
2023
                bitPos = ((Integer) val.get(0)).intValue();
2024

    
2025
                val = DwgUtil.getRawChar(intData, bitPos);
2026
                bitPos = ((Integer) val.get(0)).intValue(); // 0x00
2027
                if (((Integer) val.get(1)).intValue() != 0x00) {
2028
                        logger.warn("Classes Section RC2 != 0x00");
2029
                }
2030

    
2031
                val = DwgUtil.testBit(intData, bitPos);
2032
                bitPos = ((Integer) val.get(0)).intValue();
2033
                if (((Boolean) val.get(1)).booleanValue() != true) {
2034
                        logger.warn("Classes Section B != true");
2035
                }
2036

    
2037
                int maxBit = size * 8;
2038

    
2039
                while ((bitPos + 8) < maxBit) {
2040
                        val = DwgUtil.getBitShort(intData, bitPos);
2041
                        bitPos = ((Integer) val.get(0)).intValue();
2042
                        int classNum = ((Integer) val.get(1)).intValue();
2043

    
2044
                        val = DwgUtil.getBitShort(intData, bitPos);
2045
                        bitPos = ((Integer) val.get(0)).intValue();
2046
                        int version = ((Integer) val.get(1)).intValue();
2047

    
2048
                        val = DwgUtil.getTextString(intData, bitPos);
2049
                        bitPos = ((Integer) val.get(0)).intValue();
2050
                        String appName = (String) val.get(1);
2051

    
2052
                        val = DwgUtil.getTextString(intData, bitPos);
2053
                        bitPos = ((Integer) val.get(0)).intValue();
2054
                        String cPlusPlusName = (String) val.get(1);
2055

    
2056
                        val = DwgUtil.getTextString(intData, bitPos);
2057
                        bitPos = ((Integer) val.get(0)).intValue();
2058
                        String dxfName = (String) val.get(1);
2059

    
2060
                        val = DwgUtil.testBit(intData, bitPos);
2061
                        bitPos = ((Integer) val.get(0)).intValue();
2062
                        boolean isZombie = ((Boolean) val.get(1)).booleanValue();
2063

    
2064
                        val = DwgUtil.getBitShort(intData, bitPos);
2065
                        bitPos = ((Integer) val.get(0)).intValue();
2066
                        int id = ((Integer) val.get(1)).intValue();
2067

    
2068
                        val = DwgUtil.getBitLong(intData, bitPos);
2069
                        bitPos = ((Integer) val.get(0)).intValue();
2070
                        int numberObject = ((Integer) val.get(1)).intValue();
2071

    
2072
                        val = DwgUtil.getBitShort(intData, bitPos);
2073
                        bitPos = ((Integer) val.get(0)).intValue();
2074
                        int DwgVersion = ((Integer) val.get(1)).intValue();
2075

    
2076
                        val = DwgUtil.getBitShort(intData, bitPos);
2077
                        bitPos = ((Integer) val.get(0)).intValue();
2078
                        int maintenanceVersion = ((Integer) val.get(1)).intValue();
2079

    
2080
                        val = DwgUtil.getBitLong(intData, bitPos);
2081
                        bitPos = ((Integer) val.get(0)).intValue();
2082
                        int unknown1 = ((Integer) val.get(1)).intValue();
2083

    
2084
                        val = DwgUtil.getBitLong(intData, bitPos);
2085
                        bitPos = ((Integer) val.get(0)).intValue();
2086
                        int unknown2 = ((Integer) val.get(1)).intValue();
2087

    
2088
                        DwgClass2004 dwgClass = new DwgClass2004(classNum, version,
2089
                                        appName, cPlusPlusName, dxfName, isZombie, id,
2090
                                        numberObject, DwgVersion, maintenanceVersion, unknown1,
2091
                                        unknown2);
2092
                        dwgFile.addDwgClass(dwgClass);
2093

    
2094
                }// while
2095

    
2096
                decompressedBB.order(ByteOrder.nativeOrder());
2097
                byte[] lastSentinnel = new byte[16];
2098
                decompressedBB.get(lastSentinnel);
2099
                if (lastSentinnel[0] != 0x72)
2100
                        logger.warn("lastSentinnel[0] != 0x72");
2101
                if (lastSentinnel[1] != 0x5e)
2102
                        logger.warn("lastSentinnel[1] != 0x5e");
2103
                if (lastSentinnel[2] != 0x3b)
2104
                        logger.warn("lastSentinnel[2] != 0x3b");
2105
                if (lastSentinnel[3] != 0x47)
2106
                        logger.warn("lastSentinnel[3] != 0x47");
2107
                if (lastSentinnel[4] != 0x3b)
2108
                        logger.warn("lastSentinnel[4] != 0x3b");
2109
                if (lastSentinnel[5] != 0x56)
2110
                        logger.warn("lastSentinnel[5] != 0x56");
2111
                if (lastSentinnel[6] != 0x07)
2112
                        logger.warn("lastSentinnel[6] != 0x07");
2113
                if (lastSentinnel[7] != 0x3a)
2114
                        logger.warn("lastSentinnel[7] != 0x3a");
2115
                if (lastSentinnel[8] != 0x3f)
2116
                        logger.warn("lastSentinnel[8] != 0x3f");
2117
                if (lastSentinnel[9] != 0x23)
2118
                        logger.warn("lastSentinnel[9] != 0x23");
2119
                if (lastSentinnel[10] != 0x0b)
2120
                        logger.warn("lastSentinnel[10] != 0x0b");
2121
                if ((lastSentinnel[11] & 0xFF) != 0xa0)
2122
                        logger.warn("lastSentinnel[11] != 0xa0");
2123
                if (lastSentinnel[12] != 0x18)
2124
                        logger.warn("lastSentinnel[12] != 0x18");
2125
                if (lastSentinnel[13] != 0x30)
2126
                        logger.warn("lastSentinnel[13] != 0x30");
2127
                if (lastSentinnel[14] != 0x49)
2128
                        logger.warn("lastSentinnel[14] != 0x49");
2129
                if (lastSentinnel[15] != 0x75)
2130
                        logger.warn("lastSentinnel[15] != 0x75");
2131
        }
2132

    
2133
        /**
2134
         *
2135
         * @param bb
2136
         *            ByteBuffer containing the opened DWG File
2137
         */
2138
        private void readDwgR2004ObjectOffsets(ByteBuffer bb) {
2139

    
2140
                ByteBuffer decompressedBB = readSection(bb,"AcDb:Handles");
2141
                decompressedBB.position(0);
2142

    
2143
                short size;
2144

    
2145
                byte[] dataBytes;
2146
                int[] data;
2147
                int bitPos = 0;
2148
                int bitMax;
2149

    
2150

    
2151
                do {
2152
                        bitPos = 0;
2153
                        decompressedBB.order(ByteOrder.BIG_ENDIAN);
2154
                        size = decompressedBB.getShort();
2155
                        decompressedBB.order(ByteOrder.LITTLE_ENDIAN);
2156
                        if (size == 2)
2157
                                break;
2158
                        dataBytes = new byte[size-2];
2159
                        decompressedBB.get(dataBytes);
2160
                        data = DwgUtil.bytesToMachineBytes(dataBytes);
2161
                        bitMax = (size - 2) * 8;
2162
                        int lastHandle = 0;
2163
                        int lastLoc = 0;
2164
                        while (bitPos < bitMax) {
2165
                                ArrayList v = DwgUtil.getModularChar(data, bitPos);
2166
                                bitPos = ((Integer) v.get(0)).intValue();
2167
                                int handle = ((Integer) v.get(1)).intValue();
2168
                                if(handle<0){
2169
                                        logger.warn("offset negativo");
2170
                                        handle = - handle;
2171
                                }
2172
                                lastHandle = lastHandle + handle;
2173

    
2174
                                v = DwgUtil.getModularChar(data, bitPos);
2175
                                bitPos = ((Integer) v.get(0)).intValue();
2176
                                int loc = ((Integer) v.get(1)).intValue();
2177
                                lastLoc = lastLoc + loc;
2178

    
2179
                                dwgFile.addDwgObjectOffset(lastHandle, lastLoc);
2180

    
2181
                        }// while
2182
                        decompressedBB.getShort(); //crc
2183

    
2184
                } while (size != 2);
2185

    
2186
                return;
2187

    
2188
        }
2189

    
2190
        /**
2191
         * @return the decompressed data of a logical section,
2192
         * joining up all the physical sections belonging to it .
2193
         * @param ByteBuffer
2194
         *            Containing the opened dwg file
2195
         * @param compressedSize
2196
         *            size of the compressed data
2197
         * @param decompressedSize
2198
         *            size of the decompressed data
2199
         * @param CheckSum
2200
         */
2201
        protected ByteBuffer readSection(ByteBuffer bb, String name) {
2202

    
2203
                Section[] foundSections = findSections(name);
2204
                ByteBuffer fullSectionDecompressedBB = null;
2205
                ByteBuffer sectionDecompressedData = null;
2206
                int numberOfFoundSections = foundSections.length;
2207
                if ( numberOfFoundSections == 0) {
2208
                        logger.warn("No se han encontrado secciones llamadas " + name);
2209
                } else {
2210
                        Section section;
2211
                        int decompressedSize = foundSections[0].getMaxDecompressedSize();
2212

    
2213
                        fullSectionDecompressedBB = ByteBuffer.allocate(decompressedSize * numberOfFoundSections);
2214
                        fullSectionDecompressedBB.position(0);
2215

    
2216
                        for(int i=0; i<numberOfFoundSections; i++){
2217
                                section = (Section)foundSections[i];
2218

    
2219
                                int offset = section.getAddress();
2220
                                bb.position(offset);
2221
                                bb.order(ByteOrder.nativeOrder());
2222
                                byte[] encrypted = new byte[32];
2223
                                bb.get(encrypted); // We get the Encrypted Section Header
2224

    
2225
                                int[] decrypted = decryptSectionHeader(encrypted, offset);
2226
                                /*
2227
                                 * decrypted[0] = SectionType
2228
                                 * decrypted[1] = Data Size
2229
                                 * decrypted[2] = Section Size
2230
                                 * decrypted[3] = Start Offset
2231
                                 * decrypted[4] = Unknown
2232
                                 * decrypted[5] = CheckSum1
2233
                                 * decrypted[6] = CheckSum2
2234
                                 * decrypted[7] = ???
2235
                                 *
2236
                                 * Lo de arriba es lo de la documentacion pero yo creo [Paco]:
2237
                                 *
2238
                                 * decrypted[0] = ???
2239
                                 * decrypted[1] = SectionType
2240
                                 * decrypted[2] = Data Size
2241
                                 * decrypted[3] = Section Size
2242
                                 * decrypted[4] = Start Offset
2243
                                 * decrypted[5] = Unknown
2244
                                 * decrypted[6] = CheckSum1
2245
                                 * decrypted[7] = CheckSum2
2246
                                 *
2247
                                 */
2248

    
2249
                                if ( decrypted[1] != section.getType()){
2250
                                        logger.warn("Discrepancia en el tipo de seccion: " + section.getType() +" , " + decrypted[1] );
2251
                                }
2252
                                if ( decrypted[2] != section.getDataSize()){
2253
                                        logger.warn("Discrepancia en el tama?o de los datos de la seccion: " + section.getDataSize() +" , " + decrypted[2] );
2254
                                }
2255
                                if ( decrypted[3] != section.getSize()){
2256
                                        logger.warn("Discrepancia en el tama?o de la seccion: " + section.getSize() +" , " + decrypted[3] );
2257
                                }
2258
                                if ( decrypted[4] != section.getStartOffset()){
2259
                                        logger.warn("Discrepancia en el start offset de la seccion: " + section.getStartOffset() +" , " + decrypted[4] );
2260
                                }
2261

    
2262
                                decompressedSize = section.getMaxDecompressedSize();
2263
                                sectionDecompressedData = readCompressedSection(bb, decrypted[2],        decompressedSize, 0);
2264
                                sectionDecompressedData.position(0);
2265
                                section.setDecompressedData(sectionDecompressedData);
2266
                                if (fullSectionDecompressedBB.position() != section.getStartOffset()){
2267
                                        logger.warn("Desincronizaci?n entre el start offset de la seccion y la posici?n del ByteBuffer compuesto: " + section.getStartOffset() +" , " + fullSectionDecompressedBB.position() );
2268
                                }
2269
                                fullSectionDecompressedBB.put(section.getDecompressedData());
2270
                        }
2271
                }
2272
                return fullSectionDecompressedBB;
2273

    
2274
        }
2275

    
2276
        /**
2277
         * Reads all the object referenced in the object map section of the DWG file
2278
         * (using their object file obsets)
2279
         */
2280
        protected void readDwgR2004Objects() {
2281

    
2282
                ByteBuffer decompressedBB = readSection(bb, "AcDb:AcDbObjects");
2283
                if (decompressedBB != null){
2284
                        decompressedBB.position(0);
2285

    
2286
                        for (int i = 0; i < dwgFile.getDwgObjectOffsets().size(); i++) {
2287
                                try {
2288
                                        DwgObjectOffset doo = (DwgObjectOffset) dwgFile.getDwgObjectOffsets().get(i);
2289

    
2290
                                        DwgObject obj = readDwgR2004Object(decompressedBB, doo.getOffset(), i);
2291
                                        /*
2292
                                         * azabala: las entidades DWG no implementadas no nos aportan
2293
                                         * nada (aunque la sigo leyendo por si aparecen problemas de
2294
                                         * puntero de fichero) No considero por tanto los DwgObject if
2295
                                         * (obj != null) { dwgFile.addDwgObject(obj); }
2296
                                         *
2297
                                         * paco: propongo reconsiderar esto. Si no cargamos todos los
2298
                                         * objetos podemos tener problemas con las subentities.
2299
                                         */
2300
                                        if (obj != null && obj.getClass() != DwgObject.class) {
2301
                                                dwgFile.addDwgObject(obj);
2302
                                        }
2303
                                } catch (Exception e) {
2304
                                        logger.error(e);
2305
                                        continue;
2306
                                }
2307
                        }// for
2308
                }
2309

    
2310
        }
2311

    
2312
        /**
2313
         * Read commun parameters for an Object
2314
         *
2315
         * @param offset
2316
         *            Object's address
2317
         * @param index
2318
         *            object identifier
2319
         * @return the object
2320
         */
2321
        protected DwgObject readDwgR2004Object(ByteBuffer bb, int offset, int index) {
2322
                DwgObject obj = null;
2323
                try {
2324
                        if (offset >= bb.capacity()) {
2325
                                logger.warn("Posible error leyendo un objeto: capacity = "
2326
                                                + bb.capacity() + " offset = " + offset);
2327
                                return null;
2328
                        }
2329
                        bb.position(offset);
2330
                        int size = DwgUtil.getModularShort(bb);
2331

    
2332

    
2333
                        //FIXME: Esto es para saltarse posibles objetos defectuosos que nos
2334
                        //impedir?an ver el resto del archivo
2335
                        if (size == 0 || size>29696) {
2336
                                logger.warn("Posible error leyendo un objeto: size = "+size);
2337
                                return null;
2338
                        }
2339
                        if (offset + (size*8) >= bb.capacity()) {
2340
                                logger.warn("Posible error leyendo un objeto: capacity = "
2341
                                                + bb.capacity() + " offset = " + offset + " size = "+size);
2342
                                return null;
2343
                        }
2344

    
2345
                        bb.order(ByteOrder.LITTLE_ENDIAN);
2346
                        byte[] data = new byte[size];
2347
                        int[] intData = new int[size];
2348

    
2349
                        bb.get(data);
2350
                        try {
2351
                                intData = DwgUtil.toIntArray(data);
2352
                        } catch (Exception e) {
2353
                                logger.error("Error leyendo un objeto: size = " + size, e);
2354
                                return null;
2355
                        }
2356

    
2357
                        int bitPos = 0;
2358
                        ArrayList v = DwgUtil.getBitShort(intData, bitPos);
2359
                        bitPos = ((Integer) v.get(0)).intValue();
2360
                        int type = ((Integer) v.get(1)).intValue(); // the type of object
2361

    
2362
                        obj = DwgObjectFactory.getInstance().create(type, index);
2363

    
2364
                        /*
2365
                         * This if is entered to check if the type of the object is a
2366
                         * non-fixed value
2367
                         */
2368
                        if (obj == null) {
2369
                                logger.info("dwgFileVR2004Reader: Entrando en Objeto Nulo");
2370
                                if (type >= 500) {
2371
                                        int newIndex = type - 500;
2372
                                        if (newIndex < (dwgFile.getDwgClasses().size() - 1)) {
2373
                                                DwgClass2004 dwgClass = (DwgClass2004) dwgFile.getDwgClasses().get(newIndex);
2374
                                                String dxfEntityName = dwgClass.getDxfName();
2375
                                                obj = DwgObjectFactory.getInstance().create(dxfEntityName, index);
2376

    
2377
                                                if (obj == null) {
2378
                                                        logger.info(dxfEntityName
2379
                                                                        + " todavia no est? implementado");
2380
                                                        return null;
2381
                                                }// if
2382
                                        }// if newIndex
2383
                                        else {
2384
                                                return null;
2385
                                        }
2386
                                } else {
2387
                                        logger.info("dwgFileVR2004Reader: Encontrado tipo " + type);
2388
                                        return null;
2389
                                }
2390
                        }
2391
                        obj.setAddress(offset); // we set the address for the object. This
2392
                        // time there is no mistake
2393
                        obj.setVersion(dwgFile.getDwgVersion());
2394

    
2395
                        v = DwgUtil.getRawLong(intData, bitPos);
2396
                        bitPos = ((Integer) v.get(0)).intValue();
2397
                        int objBSize = ((Integer) v.get(1)).intValue();
2398
                        obj.setSizeInBits(objBSize);
2399

    
2400
                        DwgHandleReference entityHandle = new DwgHandleReference();
2401
                        bitPos = entityHandle.read(intData, bitPos);
2402
                        obj.setHandle(entityHandle);
2403

    
2404
                        v = DwgUtil.readExtendedData(intData, bitPos);
2405
                        bitPos = ((Integer) v.get(0)).intValue();
2406
                        ArrayList extData = (ArrayList) v.get(1);
2407
                        obj.setExtendedData(extData);
2408

    
2409
                        boolean gflag = obj.isGraphicsFlag();
2410
                        if (gflag) {
2411
                                //lee un flag boolean
2412
                                v = DwgUtil.testBit(intData, bitPos);
2413
                                bitPos = ((Integer) v.get(0)).intValue();
2414
                                boolean val = ((Boolean) v.get(1)).booleanValue();
2415
                                //si hay imagen asociada, se lee por completo
2416
                                if (val) {
2417
                                        v = DwgUtil.getRawLong(intData, bitPos);
2418
                                        bitPos = ((Integer) v.get(0)).intValue();
2419
                                        size = ((Integer) v.get(1)).intValue();
2420
                                        int bgSize = size * 8;
2421
                                        Integer giData = (Integer) DwgUtil.getBits(intData, bgSize,
2422
                                                        bitPos);
2423
                                        obj.setGraphicData(giData.intValue());
2424
                                        bitPos = bitPos + bgSize;
2425
                                }
2426
                        }
2427
                        if(obj.getClass() != DwgObject.class)
2428
                                readSpecificObject2004(obj, intData, bitPos);
2429

    
2430
                } catch (RuntimeException e) {
2431
                        e.printStackTrace();
2432
                        return null;
2433
                } catch (CorruptedDwgEntityException e) {
2434
                        // TODO Auto-generated catch block
2435
                        e.printStackTrace();
2436
                        return null;
2437
                }
2438
                return obj;
2439
        }
2440

    
2441
        /**
2442
         * Read a specific object depending on its type
2443
         *
2444
         * @param obj
2445
         *            the object to read
2446
         * @param data
2447
         *            Data of the object
2448
         * @param bitPos
2449
         *            Position where start reading
2450
         * @throws RuntimeException
2451
         * @throws CorruptedDwgEntityException
2452
         */
2453
        private void readSpecificObject2004(DwgObject obj, int[] data, int bitPos)
2454
                        throws RuntimeException, CorruptedDwgEntityException {
2455

    
2456
                DwgObjectReaderPool pool = DwgObjectReaderPool.getInstance();
2457
                IDwgObjectReader reader = pool.get(obj, "2004");
2458
                if (reader != null) {
2459
                        // reader.setFileReader(this);
2460
                        reader.readSpecificObj(data, bitPos, obj);
2461
                } else {
2462
                        logger.warn("No se ha implementado la lectura de "
2463
                                        + obj.getClass().getName() + ", code=" + obj.getType());
2464
                }
2465
        }
2466

    
2467

    
2468
        /**
2469
         * Reads the Section Map and fills the Sections Array with the sections
2470
         * found
2471
         */
2472
        protected void readDwgR2004SectionMap(ByteBuffer bb) {
2473
                bb.order(ByteOrder.LITTLE_ENDIAN);
2474
                bb.position(sectionMapAddress);
2475
                ByteBuffer dData = readSystemSection(bb);
2476
                dData.order(ByteOrder.LITTLE_ENDIAN);
2477
                dData.position(0);
2478

    
2479
                int sectionNumber;
2480
                int gapNumber = 0;
2481
                sections = new Section[sectionAmount + 1];
2482
                gaps = new Gap[gapAmount];
2483

    
2484
                sections[0] = new Section();
2485
                sections[0].setNumber(0);
2486
                sections[0].setSize(0);
2487
                sections[0].setAddress(0x100);
2488

    
2489
                int size=0;
2490
                int previousSize=0;
2491

    
2492
                /*
2493
                 * We start reading the section map once decompressed. this usually
2494
                 * gives a pair of SectionNumber/SectionSize unless a Gap (negative
2495
                 * section number) is found
2496
                 */
2497
                for (int i = 1; i <= sectionAmount; i++) {
2498
                        previousSize=size;
2499
                        size=0;
2500
                        sections[i] = new Section();
2501
                        sectionNumber = dData.getInt();
2502
                        while (sectionNumber < 0) {
2503
                                if (gapNumber >= gapAmount) {
2504
                                        logger.warn("ERROR: Se han encontrado mas gaps de los definidos");
2505
                                }
2506
                                gaps[gapNumber] = new Gap();
2507
                                int gapSize = dData.getInt();
2508
                                size += gapSize;
2509
                                gaps[gapNumber].setSize(gapSize);
2510
                                gaps[gapNumber].setParent(dData.getInt());
2511
                                gaps[gapNumber].setLeft(dData.getInt());
2512
                                gaps[gapNumber].setRight(dData.getInt());
2513
                                gaps[gapNumber].setZero(dData.getInt());
2514
                                gapNumber++;
2515
                                sectionNumber = dData.getInt();
2516
                        }
2517

    
2518
                        if (sectionNumber == sectionInfoId) {
2519
                                // We keep this index so we can localize the Section Info
2520
                                sectionInfoIndex = i;
2521
                        }
2522
                        sections[i].setNumber(sectionNumber);
2523
                        int sectionSize = dData.getInt();
2524
                        sections[i].setSize(sectionSize);
2525
                        size += sectionSize;
2526
                        if (i == 1) {
2527
                                sections[i].setAddress(0x100);
2528
                        } else {
2529
                                sections[i].setAddress(sections[i - 1].getAddress()
2530
                                                + previousSize);
2531
                        }
2532
                }
2533
        }
2534

    
2535
        /**
2536
         * @return Returns the decompressed data of SectionMap and Section Info.
2537
         * @param ByteBuffer
2538
         *            containing the dwg opened file
2539
         */
2540
        protected ByteBuffer readSystemSection(ByteBuffer bb) {
2541

    
2542
                int sectionType = bb.getInt();
2543
                int decompressedSize = bb.getInt();
2544
                int compressedSize = bb.getInt();
2545
                int compressionType = bb.getInt();
2546
                int checksum = bb.getInt();
2547

    
2548

    
2549
                return readCompressedSection(bb, compressedSize, decompressedSize, checksum);
2550

    
2551
        }
2552

    
2553
        /**
2554
         * @return the decompressed data of a compressed section.
2555
         * @param ByteBuffer
2556
         *            Containing the opend dwg file
2557
         * @param compressedSize
2558
         *            size of the compressed data
2559
         * @param decompressedSize
2560
         *            size of the decompressed data
2561
         * @param CheckSum
2562
         */
2563
        protected ByteBuffer readCompressedSection(ByteBuffer bb, int compressedSize, int decompressedSize, int checksum) {
2564
                long calcSize = 0;
2565
                ByteBuffer decompressedData;
2566
                decompressedData = ByteBuffer.allocate(decompressedSize);
2567
                decompressedData.order(ByteOrder.LITTLE_ENDIAN);
2568
                decompressedData.position(0);
2569

    
2570
                int opcodes = 0;
2571
                byte opcode1 = bb.get();
2572
                byte opcode2 = 0;
2573
                boolean opcode2valid = false;
2574
                int literalLength = 0;
2575
                int lls = 0;
2576
                int compressedBytes = 0; // Number of "compressed" bytes that are to be copied to this
2577
                                         // location from a previous location in the uncompressed data stream
2578

    
2579
                int compOffset = 0; // Offset backwards from the current location in the decompressed data stream,
2580
                                    // where the "compressed" bytes should be copied from.
2581

    
2582
                int litCount = 0; // Number of uncompressed or literal bytes to be copied from the input stream,
2583
                                  // following the addition of the compressed bytes.
2584
                int[] twoBytesOffset;
2585
                byte b;
2586

    
2587
                try {
2588
                        if (((opcode1 & 0xFF) >= 0x00) && ((opcode1 & 0xFF) <= 0x0F)) {
2589
                                literalLength = readLiteralLength(bb, opcode1);
2590
                                lls++;
2591
                                if (literalLength != 0) { // Copy the first sequence of uncompressed(literal) data
2592
                                        for (int i = 0; i < literalLength; i++) {
2593
                                                b = bb.get();
2594
                                                decompressedData.put(b);
2595
                                        }
2596
                                        opcode1 = bb.get(); // get the first opcode
2597
                                }
2598
                                calcSize = calcSize + literalLength;
2599

    
2600
                        } else {
2601
                                logger.error("Error leyendo el literal Length");
2602
                        }
2603

    
2604
                        // We start treating the opcodes
2605

    
2606
                        while (opcode1 != 0x11) {
2607

    
2608
                                if ((opcode1 & 0xFF) >= 0x00 && (opcode1 & 0xFF) <= 0x0F) {
2609

    
2610
                                        logger.warn("Posible error leyendo el opcode " + opcode1);
2611
                                        decompressedData.put(opcode1); // ???
2612
                                        if (opcode2valid) {
2613
                                                opcode1 = opcode2;
2614
                                                opcode2valid = false;
2615
                                        } else {
2616
                                                opcode1 = bb.get();
2617
                                        }
2618
                                        continue;
2619
                                } else {
2620
                                        compressedBytes = 0;
2621
                                        compOffset = 0;
2622
                                        litCount = 0;
2623
                                        opcodes++;
2624
                                        if ((opcode1 & 0xFF) == 0x10) {
2625
                                                compressedBytes = readLongCompressionOffset(bb) + 9;
2626
                                                twoBytesOffset = readTwoByteOffset(bb);
2627
                                                compOffset = twoBytesOffset[0] + 0x3FFF;
2628
                                                litCount = twoBytesOffset[1]; // this can take values from 0 to 3.
2629
                                                opcode2 = bb.get(); // we get the next opcode
2630
                                                opcode2valid = true;
2631
                                                if (litCount == 0) { // if litCount is 0, it is read as the next literal length
2632
                                                        litCount = readLiteralLength(bb, opcode2);
2633
                                                        opcode2valid = false;
2634
                                                        if (litCount != 0) {
2635
                                                                opcode2 = bb.get();
2636
                                                                opcode2valid = true;
2637
                                                        }
2638
                                                }
2639
                                        } else if ((opcode1 & 0xFF) >= 0x12
2640
                                                        && (opcode1 & 0xFF) <= 0x17) {
2641
                                                compressedBytes = (opcode1 & 0x0F) + 2;
2642
                                                twoBytesOffset = readTwoByteOffset(bb);
2643
                                                compOffset = twoBytesOffset[0] + 0x3FFF;
2644
                                                litCount = twoBytesOffset[1]; // this can take values from 0 to 3.
2645
                                                opcode2 = bb.get(); // we get the next opcode
2646
                                                opcode2valid = true;
2647
                                                if (litCount == 0) { // if litCount is 0, it is read
2648
                                                        // as the next literal length
2649
                                                        litCount = readLiteralLength(bb, opcode2);
2650
                                                        opcode2valid = false;
2651
                                                        if (litCount != 0) {
2652
                                                                opcode2 = bb.get();
2653
                                                                opcode2valid = true;
2654
                                                        }
2655
                                                }
2656
                                        } else if ((opcode1 & 0xFF) == 0x18) {
2657
                                                // Fuera de las especificaciones de OpenDWG pero
2658
                                                // segun chiuinan2, un usuario del foro (en japones):
2659
                                                // http://www.programmer-club.com/pc2020v5/Forum/ShowSameTitleN.asp?URL=N&board_pc2020=general&index=16&id=4664&mode=&type_pc2020=sametitleLevel-2
2660
                                                // hay que hacer este tratamiento al recibir estos opcodes
2661

    
2662
                                                compressedBytes = readLongCompressionOffset(bb) + 9;
2663
                                                twoBytesOffset = readTwoByteOffset(bb);
2664
                                                compOffset = twoBytesOffset[0] + 0x7FFF;
2665
                                                litCount = twoBytesOffset[1]; // this can take values from 0 to 3.
2666
                                                opcode2 = bb.get(); // we get the next opcode
2667
                                                opcode2valid = true;
2668
                                                if (litCount == 0) { // if litCount is 0, it is read as the next literal length
2669
                                                        litCount = readLiteralLength(bb, opcode2);
2670
                                                        opcode2valid = false;
2671
                                                        if (litCount != 0) {
2672
                                                                opcode2 = bb.get();
2673
                                                                opcode2valid = true;
2674
                                                        }
2675
                                                }
2676
                                        } else if ((opcode1 & 0xFF) >= 0x19
2677
                                                        && (opcode1 & 0xFF) <= 0x1f) {
2678
                                                // Fuera de las especificaciones de OpenDWG pero
2679
                                                // segun chiuinan2, un usuario del foro (en japones):
2680
                                                // http://www.programmer-club.com/pc2020v5/Forum/ShowSameTitleN.asp?URL=N&board_pc2020=general&index=16&id=4664&mode=&type_pc2020=sametitleLevel-2
2681
                                                // hay que hacer este tratamiento al recibir estos opcodes
2682

    
2683
                                                compressedBytes = (opcode1 & 0x0F) + 2;
2684
                                                twoBytesOffset = readTwoByteOffset(bb);
2685
                                                compOffset = twoBytesOffset[0] + 0x7FFF;
2686
                                                litCount = twoBytesOffset[1]; // this can take values from 0 to 3.
2687
                                                opcode2 = bb.get(); // we get the next opcode
2688
                                                opcode2valid = true;
2689
                                                if (litCount == 0) { // if litCount is 0, it is read as the next literal length
2690
                                                        litCount = readLiteralLength(bb, opcode2);
2691
                                                        opcode2valid = false;
2692
                                                        if (litCount != 0) {
2693
                                                                opcode2 = bb.get();
2694
                                                                opcode2valid = true;
2695
                                                        }
2696
                                                }
2697
                                        } else if ((opcode1 & 0xFF) == 0x20) {
2698
                                                // Fuera de las especificaciones de OpenDWG pero
2699
                                                // segun kermit un usuario del foro de openDesign hay
2700
                                                // que a?adirle 0x21
2701
                                                compressedBytes = readLongCompressionOffset(bb) + 0x21;
2702
                                                twoBytesOffset = readTwoByteOffset(bb);
2703
                                                compOffset = twoBytesOffset[0];
2704
                                                litCount = twoBytesOffset[1]; // this can take values from 0 to 3.
2705
                                                opcode2 = bb.get(); // we get the next opcode
2706
                                                opcode2valid = true;
2707
                                                if (litCount == 0) { // if litCount is 0, it is read as the next literal length
2708
                                                        litCount = readLiteralLength(bb, opcode2);
2709
                                                        opcode2valid = false;
2710
                                                        if (litCount != 0) {
2711
                                                                opcode2 = bb.get();
2712
                                                                opcode2valid = true;
2713
                                                        }
2714
                                                }
2715
                                        } else if ((opcode1 & 0xFF) >= 0x21
2716
                                                        && (opcode1 & 0xFF) <= 0x3f) {
2717
                                                compressedBytes = (opcode1 & 0xFF) - 0x1E;
2718

    
2719
                                                twoBytesOffset = readTwoByteOffset(bb);
2720
                                                compOffset = twoBytesOffset[0];
2721
                                                litCount = twoBytesOffset[1]; // this can take values from 0 to 3.
2722
                                                opcode2 = bb.get(); // we get the next opcode
2723
                                                opcode2valid = true;
2724
                                                if (litCount == 0) { // if litCount is 0, it is read as the next literal length
2725
                                                        litCount = readLiteralLength(bb, opcode2);
2726
                                                        opcode2valid = false;
2727
                                                        if (litCount != 0) {
2728
                                                                opcode2 = bb.get();
2729
                                                                opcode2valid = true;
2730
                                                        }
2731
                                                }
2732
                                        } else if ((opcode1 & 0xFF) >= 0x40
2733
                                                        && (opcode1 & 0xFF) <= 0xFF) {
2734
                                                compressedBytes = ((opcode1 & 0xF0) >> 4) - 1;
2735
                                                opcode2 = bb.get(); // we read the next byte
2736
                                                opcode2valid = true;
2737
                                                compOffset = ((opcode2 & 0xFF) << 2)
2738
                                                                | ((opcode1 & 0x0C) >> 2);
2739
                                                opcode2valid = false;
2740
                                                if ((opcode1 & 0x03) == 0x00) { // if litCount is 0, it is read as the next literal length
2741
                                                        litCount = 0;
2742
                                                        byte opcode3 = bb.get();
2743
                                                        litCount = readLiteralLength(bb, opcode3);
2744
                                                        if (litCount == 0) {
2745
                                                                opcode2 = opcode3; // if litCount = 0, the actual byte is the next opcode
2746
                                                        } else {
2747
                                                                opcode2 = bb.get(); // we get the next opcode
2748
                                                        }
2749
                                                        opcode2valid = true;
2750
                                                } else {
2751
                                                        litCount = opcode1 & 0x03;
2752
                                                        opcode2 = bb.get();
2753
                                                        opcode2valid = true;
2754
                                                }
2755
                                        } else {
2756
                                                logger.warn("Posible error de lectura de una seccion comprimida: " +
2757
                                                                "Ha aparecido un opcode1 con valor "
2758
                                                                + Integer.toHexString(opcode1 & 0xFF));
2759
                                                opcode2 = bb.get();
2760
                                                opcode2valid = true;
2761
                                        }
2762

    
2763
                                        if (compressedBytes < 0) {
2764
                                                logger.warn("Posible error de lectura de una seccion comprimida: compressedBytes < 0");
2765
                                        }
2766
                                        if (compOffset < 0) {
2767
                                                logger.warn("Posible error de lectura de una seccion comprimida: compOffset < 0");
2768
                                        }
2769
                                        if (litCount < 0) {
2770
                                                logger.warn("Posible error de lectura de una seccion comprimida: litCount < 0");
2771
                                        }
2772

    
2773
                                        if (compressedBytes > compOffset) {
2774
                                                logger.warn("Posible error en la lectura de una seccion comprimida: "
2775
                                                                                + "No parece logico que compressedBytes > compOffset");
2776
                                        }
2777
                                        if (compOffset >= decompressedData.position()) {
2778
                                                logger.warn("Posible error en la lectura de una seccion comprimida:"
2779
                                                                                + " el compOffset se sale");
2780
                                                compressedBytes = 0; // ???? Para no leer bytes comprimidos ni que se
2781
                                                // incluyan en el tama?o calculado.
2782
                                        }
2783
                                        /*
2784
                                         * We first copy the compressed bytes in our
2785
                                         * decompressedData buffer, from a position compOffset bytes
2786
                                         * backward from the current position
2787
                                         */
2788

    
2789
                                        for (int i = 0; i < compressedBytes; i++) {
2790
                                                b = decompressedData.get(decompressedData.position() - compOffset - 1);
2791
                                                decompressedData.put(b);
2792
                                        }
2793

    
2794
                                        /*
2795
                                         * Then we copy the literal bytes to our decompressedData
2796
                                         * from the input stream
2797
                                         */
2798
                                        for (int i = 0; i < litCount; i++) {
2799
                                                decompressedData.put(opcode2);
2800
                                                opcode2valid = false;
2801
                                                opcode2 = bb.get();
2802
                                                opcode2valid = true;
2803
                                        }
2804

    
2805
                                        calcSize = calcSize + compressedBytes + litCount;
2806
                                }
2807
                                opcode1 = opcode2;
2808
                                opcode2valid = false;
2809
                        }
2810

    
2811
                } catch (Exception e) {
2812
                        e.printStackTrace();
2813

    
2814
                }
2815

    
2816
                return decompressedData;
2817
        }
2818

    
2819
        /**
2820
         * @return the value of the Literal Length.
2821
         * @param ByteBuffer
2822
         *            Containing the opened dwg File.
2823
         * @param byte
2824
         *            b The opcode to calculate the Literal Length
2825
         */
2826
        private int readLiteralLength(ByteBuffer bb, byte b) {
2827
                int total = 0;
2828
                if (0x01 <= b && b <= 0x0F) {
2829
                        total = (b & 0xFF) + 3;
2830
                        return total;
2831
                } else if (b == 0x00) {
2832
                        total = 0x0F;
2833
                        b = bb.get();
2834
                        while (b == 0x00) {
2835
                                total += 0xFF;
2836
                                b = bb.get();
2837
                        }
2838
                        total += (b & 0xFF) + 3;
2839
                        return total;
2840
                } else if ((b & 0xF0) != 0) {
2841
                        /*
2842
                         * Any bit set in the high nibble indicates that the literal lenght
2843
                         * is 0, and the byte is actually the next compression opcode. This
2844
                         * is case is not possible when the first literal length is read
2845
                         */
2846
                        return 0;
2847
                }
2848
                logger.warn("Posible error de lectura: Se ha encontrado un Literal Lenght: "
2849
                                + Integer.toHexString(b & 0xFF));
2850
                return total;
2851
        }
2852

    
2853
        /**
2854
         * Common compression for different opcodes
2855
         *
2856
         * @param bb
2857
         *            ByteBuffer reading the opened DWG file
2858
         * @return the value for <code> offset </code> and <code> litCount </code>
2859
         */
2860
        private int[] readTwoByteOffset(ByteBuffer bb) {
2861
                byte firstByte = bb.get();
2862
                int[] values = new int[2];
2863
                int offset = (((firstByte & 0xFF) >> 2) | ((bb.get() & 0xFF) << 6));
2864
                int litCount = firstByte & 0x03; // This will make litCount taking values from 0 to 3
2865
                values[0] = offset;
2866
                values[1] = litCount;
2867
                return values;
2868
        }
2869

    
2870
        /**
2871
         * Common compression for different opcodes
2872
         *
2873
         * @param bb
2874
         *            ByteBuffer reading the opened DWG file
2875
         * @return the value for <code> compressedBytes </code>
2876
         */
2877
        private int readLongCompressionOffset(ByteBuffer bb) {
2878
                int value = 0;
2879
                byte b = bb.get();
2880
                while (b == 0x00) {
2881
                        value = value + 0xFF;
2882
                        b = bb.get();
2883
                }
2884
                value = value + (b & 0xFF);
2885
                return value;
2886
        }
2887

    
2888
        /**
2889
         * Generate a sequence into magicNumber to decrypt the encrypted data in the
2890
         * header
2891
         */
2892
        static void setMagicNumber() {
2893
                int size = 0x6C;
2894
                magicNumber = new byte[size];
2895
                int randseed = 1;
2896
                for (int i = 0; i < size; i++) {
2897
                        randseed *= 0x343fd;
2898
                        randseed += 0x269ec3;
2899
                        magicNumber[i] = (byte) (randseed >> 0x10);
2900
                }
2901
        }
2902

    
2903

    
2904
        public int readObjectHeader(int[] data, int offset, DwgObject dwgObject)
2905
                        throws RuntimeException, CorruptedDwgEntityException {
2906
                // TODO Auto-generated method stub
2907
                throw new UnsupportedOperationException();
2908
                // return 0;
2909
        }
2910

    
2911
        public int readObjectTailer(int[] data, int offset, DwgObject dwgObject)
2912
                        throws RuntimeException, CorruptedDwgEntityException {
2913
                // TODO Auto-generated method stub
2914
                throw new UnsupportedOperationException();
2915
                // return 0;
2916
        }
2917

    
2918
}
2919

    
2920
/**
2921
 * A section structure contains the number (identifier),size, address and name
2922
 * of the section
2923
 *
2924
 */
2925
class Section {
2926
        private int number;
2927

    
2928
        private int size;
2929

    
2930
        private int address;
2931

    
2932
        private String name;
2933

    
2934
        private int sizeOfLogicalSection;
2935

    
2936
        private int dataSize;
2937

    
2938
        private int maxDecompressedSize;
2939

    
2940
        private int compressed;
2941

    
2942
        private int type;
2943

    
2944
        private int encrypted;
2945

    
2946
        private int startOffset;
2947

    
2948
        private ByteBuffer decompressedData = null;
2949

    
2950
        /**
2951
         *
2952
         * @return number of Section
2953
         */
2954
        public int getNumber() {
2955
                return number;
2956
        }
2957

    
2958
        /**
2959
         * Sets number of section
2960
         *
2961
         * @param number
2962
         */
2963
        public void setNumber(int number) {
2964
                this.number = number;
2965
        }
2966

    
2967
        /**
2968
         *
2969
         * @return size of Section
2970
         */
2971
        public int getSize() {
2972
                return size;
2973
        }
2974

    
2975
        /**
2976
         * Sets size2 of Section
2977
         *
2978
         * @param size
2979
         */
2980
        public void setSizeOfLogicalSection(int size) {
2981
                this.sizeOfLogicalSection = size;
2982
        }
2983

    
2984
        /**
2985
         *
2986
         * @return size of Section
2987
         */
2988
        public int getSizeOfLogicalSection() {
2989
                return sizeOfLogicalSection;
2990
        }
2991

    
2992
        /**
2993
         * Sets size of Section
2994
         *
2995
         * @param size
2996
         */
2997
        public void setSize(int size) {
2998
                this.size = size;
2999
        }
3000

    
3001
        /**
3002
         *
3003
         * @return address of Section
3004
         */
3005
        public int getAddress() {
3006
                return address;
3007
        }
3008

    
3009
        /**
3010
         * Sets address of Section
3011
         *
3012
         * @param address
3013
         */
3014
        public void setAddress(int address) {
3015
                this.address = address;
3016
        }
3017

    
3018
        /**
3019
         *
3020
         * @return name of Section
3021
         */
3022
        public String getName() {
3023
                return this.name;
3024
        }
3025

    
3026
        /**
3027
         * Sets the name of Section
3028
         *
3029
         * @param name
3030
         */
3031
        public void setName(String name) {
3032
                this.name = name;
3033
        }
3034

    
3035
        /**
3036
         *
3037
         * @return size of data of the Section
3038
         */
3039
        public int getDataSize() {
3040
                return dataSize;
3041
        }
3042

    
3043
        /**
3044
         * Sets size of data of the Section
3045
         *
3046
         * @param size
3047
         */
3048
        public void setDataSize(int dataSize) {
3049
                this.dataSize = dataSize;
3050
        }
3051

    
3052
        /**
3053
         *
3054
         * @return the maximum decompressed size of section
3055
         */
3056
        public int getMaxDecompressedSize() {
3057
                return maxDecompressedSize;
3058
        }
3059

    
3060
        /**
3061
         * Sets the maximum decompressed size of section
3062
         *
3063
         * @param number
3064
         */
3065
        public void setMaxDecompressedSize(int maxDecompressedSize) {
3066
                this.maxDecompressedSize = maxDecompressedSize;
3067
        }
3068

    
3069
        /**
3070
         *
3071
         * @return compressed of section
3072
         */
3073
        public int getCompressed() {
3074
                return compressed;
3075
        }
3076

    
3077
        /**
3078
         * Sets compressed of section
3079
         *
3080
         * @param number
3081
         */
3082
        public void setCompressed(int compressed) {
3083
                this.compressed = compressed;
3084
        }
3085

    
3086
        /**
3087
         *
3088
         * @return type of Section
3089
         */
3090
        public int getType() {
3091
                return type;
3092
        }
3093

    
3094
        /**
3095
         * Sets type of section
3096
         *
3097
         * @param number
3098
         */
3099
        public void setType(int type) {
3100
                this.type = type;
3101
        }
3102

    
3103
        /**
3104
         *
3105
         * @return encrypted of Section
3106
         */
3107
        public int getEncrypted() {
3108
                return encrypted;
3109
        }
3110

    
3111
        /**
3112
         * Sets encrypted of section
3113
         *
3114
         * @param number
3115
         */
3116
        public void setEncrypted(int encrypted) {
3117
                this.encrypted = encrypted;
3118
        }
3119

    
3120
        /**
3121
         * Sets startOffset of Section
3122
         *
3123
         * @param size
3124
         */
3125
        public void setStartOffset(int startOffset) {
3126
                this.startOffset = startOffset;
3127
        }
3128

    
3129
        /**
3130
         *
3131
         * @return startOffset of Section
3132
         */
3133
        public int getStartOffset() {
3134
                return startOffset;
3135
        }
3136

    
3137
        /**
3138
         * Sets decompressedData of Section
3139
         *
3140
         * @param decompressedData
3141
         */
3142
        public void setDecompressedData(ByteBuffer decompressedData) {
3143
                this.decompressedData = decompressedData;
3144
        }
3145

    
3146
        /**
3147
         *
3148
         * @return decompressedData of Section
3149
         */
3150
        public ByteBuffer getDecompressedData() {
3151
                return decompressedData;
3152
        }
3153

    
3154

    
3155
}
3156

    
3157
/**
3158
 * A gap structure contains the size, parent, left, right and zero
3159
 * of the gap
3160
 *
3161
 */
3162
class Gap {
3163
        private int size;
3164

    
3165
        private int parent;
3166

    
3167
        private int left;
3168

    
3169
        private int right;
3170

    
3171
        private int zero;
3172

    
3173
        public int getParent() {
3174
                return parent;
3175
        }
3176

    
3177
        /**
3178
         * Sets parent of section
3179
         *
3180
         * @param parent
3181
         */
3182
        public void setParent(int parent) {
3183
                this.parent = parent;
3184
        }
3185

    
3186
        /**
3187
         *
3188
         * @return left of Section
3189
         */
3190
        public int getLeft() {
3191
                return left;
3192
        }
3193

    
3194
        /**
3195
         * Sets left of section
3196
         *
3197
         * @param left
3198
         */
3199
        public void setLeft(int left) {
3200
                this.left = left;
3201
        }
3202

    
3203
        /**
3204
         *
3205
         * @return right of Section
3206
         */
3207
        public int getRight() {
3208
                return right;
3209
        }
3210

    
3211
        /**
3212
         * Sets right of section
3213
         *
3214
         * @param right
3215
         */
3216
        public void setRight(int right) {
3217
                this.right = right;
3218
        }
3219

    
3220
        /**
3221
         *
3222
         * @return zero of Section
3223
         */
3224
        public int getZero() {
3225
                return zero;
3226
        }
3227

    
3228
        /**
3229
         * Sets zero of section
3230
         *
3231
         * @param zero
3232
         */
3233
        public void setZero(int zero) {
3234
                this.zero = zero;
3235
        }
3236

    
3237
        /**
3238
         *
3239
         * @return size of Section
3240
         */
3241
        public int getSize() {
3242
                return size;
3243
        }
3244

    
3245
        /**
3246
         * Sets size of section
3247
         *
3248
         * @param size
3249
         */
3250
        public void setSize(int size) {
3251
                this.size = size;
3252
        }
3253
}