From: Evgeniy Berlog Date: Mon, 18 Jun 2012 12:02:36 +0000 (+0000) Subject: fixed bug in EscherAggregate if sheet contains no shapes X-Git-Tag: 3.10-beta1~161^2~25 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=25ceb36664b1ca6eab23ff981551236d933158b4;p=poi.git fixed bug in EscherAggregate if sheet contains no shapes git-svn-id: https://svn.apache.org/repos/asf/poi/branches/gsoc2012@1351309 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/record/EscherAggregate.java b/src/java/org/apache/poi/hssf/record/EscherAggregate.java index e65fd0333d..f1b470398f 100644 --- a/src/java/org/apache/poi/hssf/record/EscherAggregate.java +++ b/src/java/org/apache/poi/hssf/record/EscherAggregate.java @@ -491,7 +491,8 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { // the first one because it's the patriach). pos = offset; int writtenEscherBytes = 0; - for (int i = 1; i < shapes.size(); i++) { + int i; + for (i = 1; i < shapes.size(); i++) { int endOffset = (Integer) spEndingOffsets.get(i) - 1; int startOffset; if (i == 1) @@ -515,10 +516,15 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { pos += writeDataIntoDrawingRecord(0, drawingData, writtenEscherBytes, pos, data, i); } } + if ((pos - offset) < buffer.length-1){ + byte[] drawingData = new byte[buffer.length - (pos - offset)]; + System.arraycopy(buffer, (pos - offset), drawingData, 0, drawingData.length); + pos += writeDataIntoDrawingRecord(0, drawingData, writtenEscherBytes, pos, data, i); + } // write records that need to be serialized after all drawing group records - for (int i = 0; i < tailRec.size(); i++) { - Record rec = (Record) tailRec.get(i); + for (i = 0; i < tailRec.size(); i++) { + Record rec = tailRec.get(i); pos += rec.serialize(pos, data); } int bytesWritten = pos - offset; @@ -599,6 +605,9 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { } int drawingRecordSize = rawEscherSize + (shapeToObj.size()) * 4; + if (rawEscherSize != 0 && spEndingOffsets.size()==1/**EMPTY**/){ + continueRecordsHeadersSize +=4; + } int objRecordSize = 0; for (Iterator iterator = shapeToObj.values().iterator(); iterator.hasNext(); ) { Record r = (Record) iterator.next();