]> source.dussan.org Git - poi.git/commitdiff
Patch from Michael to fix bug 28203
authorGlen Stampoultzis <glens@apache.org>
Sun, 27 Jun 2004 11:21:13 +0000 (11:21 +0000)
committerGlen Stampoultzis <glens@apache.org>
Sun, 27 Jun 2004 11:21:13 +0000 (11:21 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/branches/REL_2_BRANCH@353565 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/AbstractEscherHolderRecord.java

index e927175c440a1fca57a16ba63a2333678e9cfc95..b2701e3fc4fcec1878fe04e5eea8003a7836a14c 100644 (file)
@@ -32,6 +32,7 @@ import java.util.List;
  * must be subclassed for maximum benefit.
  *
  * @author Glen Stampoultzis (glens at apache.org)
+ * @author Michael Zalewski (zalewski at optonline.net)
  */
 public abstract class AbstractEscherHolderRecord
     extends Record
@@ -118,13 +119,13 @@ public abstract class AbstractEscherHolderRecord
         StringBuffer buffer = new StringBuffer();
 
         final String nl = System.getProperty("line.separator");
-        buffer.append("[" + getRecordName() + "]" + nl);
+        buffer.append('[' + getRecordName() + ']' + nl);
         for ( Iterator iterator = escherRecords.iterator(); iterator.hasNext(); )
         {
             EscherRecord r = (EscherRecord) iterator.next();
             buffer.append(r.toString());
         }
-        buffer.append("[/" + getRecordName() + "]" + nl);
+        buffer.append("[/" + getRecordName() + ']' + nl);
 
         return buffer.toString();
     }
@@ -133,29 +134,49 @@ public abstract class AbstractEscherHolderRecord
 
     public int serialize(int offset, byte[] data)
     {
-        if (escherRecords.size() == 0 && rawData != null)
+        LittleEndian.putShort( data, 0 + offset, getSid() );
+        LittleEndian.putShort( data, 2 + offset, (short) ( getRecordSize() - 4 ) );
+        if ( escherRecords.size() == 0 && rawData != null )
         {
-            System.arraycopy( rawData, 0, data, offset, rawData.length);
-            return rawData.length;
+            System.arraycopy( rawData, 0, data, offset + 4, rawData.length );
         }
         else
         {
-            collapseShapeInformation();
-
-            LittleEndian.putShort(data, 0 + offset, getSid());
-            LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
-
             int pos = offset + 4;
             for ( Iterator iterator = escherRecords.iterator(); iterator.hasNext(); )
             {
                 EscherRecord r = (EscherRecord) iterator.next();
-                pos += r.serialize(pos, data, new NullEscherSerializationListener() );
+                pos += r.serialize( pos, data, new NullEscherSerializationListener() );
             }
-
-            return getRecordSize();
         }
+        return getRecordSize();
     }
 
+//    public int serialize(int offset, byte[] data)
+//    {
+//        if (escherRecords.size() == 0 && rawData != null)
+//        {
+//            System.arraycopy( rawData, 0, data, offset, rawData.length);
+//            return rawData.length;
+//        }
+//        else
+//        {
+//            collapseShapeInformation();
+//
+//            LittleEndian.putShort(data, 0 + offset, getSid());
+//            LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
+//
+//            int pos = offset + 4;
+//            for ( Iterator iterator = escherRecords.iterator(); iterator.hasNext(); )
+//            {
+//                EscherRecord r = (EscherRecord) iterator.next();
+//                pos += r.serialize(pos, data, new NullEscherSerializationListener() );
+//            }
+//
+//            return getRecordSize();
+//        }
+//    }
+
     /**
      * Size of record (including 4 byte header)
      */
@@ -163,12 +184,10 @@ public abstract class AbstractEscherHolderRecord
     {
         if (escherRecords.size() == 0 && rawData != null)
         {
-            return rawData.length;
+            return rawData.length + 4;
         }
         else
         {
-            collapseShapeInformation();
-
             int size = 4;
             for ( Iterator iterator = escherRecords.iterator(); iterator.hasNext(); )
             {
@@ -179,10 +198,29 @@ public abstract class AbstractEscherHolderRecord
         }
     }
 
-    private void collapseShapeInformation()
-    {
-
-    }
+//
+//    /**
+//     * Size of record (including 4 byte header)
+//     */
+//    public int getRecordSize()
+//    {
+//        if (escherRecords.size() == 0 && rawData != null)
+//        {
+//            return rawData.length;
+//        }
+//        else
+//        {
+//            collapseShapeInformation();
+//
+//            int size = 4;
+//            for ( Iterator iterator = escherRecords.iterator(); iterator.hasNext(); )
+//            {
+//                EscherRecord r = (EscherRecord) iterator.next();
+//                size += r.getRecordSize();
+//            }
+//            return size;
+//        }
+//    }
 
     public abstract short getSid();