From b326756ddd7eee426d7d0e93a485ec30b6fbb5fd Mon Sep 17 00:00:00 2001
From: ?? ? <ulysseskao@ximple.com.tw>
Date: Tue, 20 Apr 2010 19:27:20 +0800
Subject: [PATCH] dgn7 write function for complex chain

---
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileReader.java |   95 ++++++-----------------------------------------
 1 files changed, 13 insertions(+), 82 deletions(-)

diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileReader.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileReader.java
index 298f2ae..4dabae4 100644
--- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileReader.java
+++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Dgn7fileReader.java
@@ -27,7 +27,7 @@
  *
  * @author Ulysses
  * @version 0.1
- * @since 2006/5/17 �U�� 01:24:10
+ * @since 2006/5/17
  */
 public class Dgn7fileReader {
     private static final Logger logger = LogManager.getLogger(Dgn7fileReader.class);
@@ -37,15 +37,15 @@
     ByteBuffer buffer;
     private ElementType fileElementType = ElementType.UNDEFINED;
     private ByteBuffer headerTransfer;
-    private final Record record = new Record();
+    private final Element.FileRecord record = new Element.FileRecord();
     private final boolean randomAccessEnabled;
     private Lock lock;
     private boolean useMemoryMappedBuffer;
     private long currentOffset = 0L;
-    private StreamLogging streamLogger = new StreamLogging("Shapefile Reader");
+    private StreamLogging streamLogger = new StreamLogging("Dgn7 Reader");
     private int maxElementId = 0;
 
-    public Dgn7fileReader(ReadableByteChannel channel, boolean strict, boolean useMemoryMapped, Lock lock)
+    public Dgn7fileReader(FileChannel channel, boolean strict, boolean useMemoryMapped, Lock lock)
         throws IOException, Dgn7fileException {
         this.channel = channel;
         this.useMemoryMappedBuffer = useMemoryMapped;
@@ -56,7 +56,7 @@
         init(strict);
     }
 
-    public Dgn7fileReader(ReadableByteChannel channel, Lock lock) throws IOException, Dgn7fileException {
+    public Dgn7fileReader(FileChannel channel, Lock lock) throws IOException, Dgn7fileException {
         this(channel, true, true, lock);
     }
 
@@ -163,7 +163,7 @@
         return randomAccessEnabled;
     }
 
-    public Record nextElement() throws IOException, Dgn7fileException {
+    public Element.FileRecord nextElement() throws IOException, Dgn7fileException {
         // need to update position
         buffer.position(this.toBufferOffset(record.end));
 
@@ -269,6 +269,7 @@
         record.length = elementLength;
         record.signature = signature;
         record.number = recordNumber;
+        record.buffer = buffer;
 
         // remember, we read one int already...
         record.end = this.toFileOffset(buffer.position()) + elementLength - 4;
@@ -322,7 +323,7 @@
         }
     }
 
-    public Record elementAt(int offset) throws IOException, UnsupportedOperationException, Dgn7fileException {
+    public Element.FileRecord elementAt(int offset) throws IOException, UnsupportedOperationException, Dgn7fileException {
         if (randomAccessEnabled) {
             this.goTo(offset);
 
@@ -517,7 +518,7 @@
                     while (reader.hasNext()) {
                         size++;
 
-                        Dgn7fileReader.Record record = reader.nextElement();
+                        Element.FileRecord record = reader.nextElement();
 
                         if (record.element() != null) {
                             Element element = (Element) record.element();
@@ -550,90 +551,20 @@
                 } catch (IOException e) {
                     logger.warn("Stop read dgn file", e);
                 } catch (Dgn7fileException e) {
-                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+                    logger.warn(e.getMessage(), e);
                 } finally {
                     reader.close();
                 }
 
-                System.out.println("count=" + count + " size=" + size);
+                logger.debug("count=" + count + " size=" + size);
                 // reader.close();
             } catch (IOException ioe) {
-                System.out.println(ioe);
-                ioe.printStackTrace();
+                logger.warn(ioe.getMessage(), ioe);
             } catch (Dgn7fileException e) {
-                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+                logger.warn(e.getMessage(), e);
             }
         }
 
         System.exit(0);
-    }
-
-    public final class Record {
-        int length;
-        int number = 0;
-        int offset;           // Relative to the whole file
-        int start = 0;    // Relative to the current loaded buffer
-        short signature = 0;
-
-        /**
-         * The minimum X value.
-         */
-        public double minX;
-
-        /**
-         * The minimum Y value.
-         */
-        public double minY;
-
-        /**
-         * The minimum Z value.
-         */
-        public double minZ;
-
-        /**
-         * The maximum X value.
-         */
-        public double maxX;
-
-        /**
-         * The maximum Y value.
-         */
-        public double maxY;
-
-        /**
-         * The maximum Z value.
-         */
-        public double maxZ;
-
-        // ElementType type;
-        int end = 0;    // Relative to the whole file
-        Object element = null;
-        IElementHandler handler;
-
-        public Object element() {
-            if (element == null) {
-                buffer.position(start);
-                buffer.order(ByteOrder.LITTLE_ENDIAN);
-
-                if (handler == null) {
-                    return null;
-                }
-
-                element = handler.read(buffer, signature, length);
-            }
-
-            return element;
-        }
-
-        public int offset() {
-            return offset;
-        }
-
-        /**
-         * A summary of the record.
-         */
-        public String toString() {
-            return "Record " + number + " length " + length + " bounds " + minX + "," + minY + " " + maxX + "," + maxY;
-        }
     }
 }

--
Gitblit v0.0.0-SNAPSHOT