mirror of
https://github.com/apache/poi.git
synced 2026-02-27 12:30:08 +08:00
Introduce getComplexSize()
To not materialize the array only to get its size
This commit is contained in:
parent
e54ba888e2
commit
c9b37678cc
@ -118,7 +118,7 @@ public final class EscherArrayProperty extends EscherComplexProperty implements
|
||||
|
||||
private void rewriteArray(int numberOfElements, boolean copyToNewLen) {
|
||||
int expectedArraySize = numberOfElements * getActualSizeOfElements(getSizeOfElements()) + FIXED_SIZE;
|
||||
resizeComplexData(expectedArraySize, copyToNewLen ? expectedArraySize : getComplexData().length);
|
||||
resizeComplexData(expectedArraySize, copyToNewLen ? expectedArraySize : getComplexSize());
|
||||
}
|
||||
|
||||
public int getNumberOfElementsInMemory() {
|
||||
@ -181,7 +181,7 @@ public final class EscherArrayProperty extends EscherComplexProperty implements
|
||||
|
||||
// the code here seems to depend on complexData already being
|
||||
// sized correctly via the constructor
|
||||
int cdLen = getComplexData().length;
|
||||
int cdLen = getComplexSize();
|
||||
int arraySize = getActualSizeOfElements(sizeOfElements) * numElements;
|
||||
if (arraySize == cdLen) {
|
||||
// The stored data size in the simple block excludes the header size
|
||||
@ -190,7 +190,7 @@ public final class EscherArrayProperty extends EscherComplexProperty implements
|
||||
}
|
||||
setComplexData(data, offset);
|
||||
}
|
||||
return getComplexData().length;
|
||||
return getComplexSize();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,7 +202,7 @@ public final class EscherArrayProperty extends EscherComplexProperty implements
|
||||
@Override
|
||||
public int serializeSimplePart(byte[] data, int pos) {
|
||||
LittleEndian.putShort(data, pos, getId());
|
||||
int recordSize = getComplexData().length;
|
||||
int recordSize = getComplexSize();
|
||||
if (!sizeIncludesHeaderSize) {
|
||||
recordSize -= 6;
|
||||
}
|
||||
|
||||
@ -135,6 +135,10 @@ public class EscherComplexProperty extends EscherProperty {
|
||||
return complexData;
|
||||
}
|
||||
|
||||
public int getComplexSize() {
|
||||
return complexSize;
|
||||
}
|
||||
|
||||
public int setComplexData(byte[] complexData) {
|
||||
return setComplexData(complexData, 0);
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ public final class EscherPropertyFactory {
|
||||
pos += eap.setArrayData(data, pos);
|
||||
} else if (p instanceof EscherComplexProperty) {
|
||||
EscherComplexProperty ecp = (EscherComplexProperty)p;
|
||||
int cdLen = ecp.getComplexData().length;
|
||||
int cdLen = ecp.getComplexSize();
|
||||
int leftover = data.length - pos;
|
||||
if (leftover < cdLen) {
|
||||
throw new IllegalStateException("Could not read complex escher property, length was " +
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user