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