From fe4bda7d456c106e1061afaa29d452e5553e9d96 Mon Sep 17 00:00:00 2001
From: ?? ? <ulysseskao@ximple.com.tw>
Date: Wed, 14 May 2008 19:40:53 +0800
Subject: [PATCH] update for EOFM-83

---
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java |   32 ++++++++++++++++++++++++--------
 1 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java
index 62ff460..10e6852 100644
--- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java
+++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java
@@ -33,12 +33,17 @@
     public static final int PRIMARY_CLASS           = 0;
     public static final int PRIMARY_RULE_CLASS      = 0;
 
-    protected short[]   raw;
-    protected byte      attrOffset = 0;
+    protected short[]       raw;
+    protected byte          attrOffset = 0;
+    protected ByteBuffer    rawBuffer;
 
-    public Element(short[] raw)
+    public Element(byte[] raw)
     {
-        this.raw = raw;
+        // this.raw = raw;
+        this.raw = new short[raw.length / 2];
+        rawBuffer = ByteBuffer.wrap(raw);
+        rawBuffer.order(ByteOrder.LITTLE_ENDIAN);
+        rawBuffer.asShortBuffer().get(this.raw);
     }
 
     public int getLineStyle()
@@ -217,6 +222,10 @@
         }
     }
 
+    protected static int getOffsetPosition(int offset)
+    {
+        return offset * 2;
+    }
 
     public static class ElementHandler implements IElementHandler
     {
@@ -234,23 +243,30 @@
 
         public Object read(ByteBuffer buffer, short signature, int length)
         {
-            byte[] dst = new byte[length - 4];
+            byte[] dst = new byte[length];
             try
             {
-                buffer.get(dst, 0, dst.length);
+                buffer.get(dst, 4, dst.length - 4);
             } catch (BufferUnderflowException exception)
             {
                 throw exception;   
             }
+
             ByteBuffer tmpBuffer = ByteBuffer.wrap(dst);
             tmpBuffer.order(ByteOrder.LITTLE_ENDIAN);
+            tmpBuffer.position(0);
+            tmpBuffer.putShort(signature);
+            tmpBuffer.putShort((short) ((length / 2) - 2));
+            
+            /*
             ShortBuffer sbuffer = tmpBuffer.asShortBuffer();
 
             short[] rawMem = new short[(length / 2)];
             sbuffer.get(rawMem, 2, rawMem.length - 2);
             rawMem[0] = signature;
             rawMem[1] = (short) ((length / 2) - 2);
-            Element elm = createElement(rawMem);
+            */
+            Element elm = createElement(dst);
 
             return elm;
         }
@@ -264,7 +280,7 @@
             return ((Element) element).raw.length;
         }
 
-        protected Element createElement(short[] raw)
+        protected Element createElement(byte[] raw)
         {
             return new Element(raw);
         }

--
Gitblit v0.0.0-SNAPSHOT