aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Volkhart <mariusvolkhart@apache.org>2021-02-28 16:47:43 +0000
committerMarius Volkhart <mariusvolkhart@apache.org>2021-02-28 16:47:43 +0000
commitb7038df14dc09a640d4c4d67820dba98f09cf7f6 (patch)
tree2337b54ea11fd9dbba0492de3fbeda1a74fedc43
parent12857e68ac370a09c2cd2745c0c97789899d7711 (diff)
downloadpoi-b7038df14dc09a640d4c4d67820dba98f09cf7f6.tar.gz
poi-b7038df14dc09a640d4c4d67820dba98f09cf7f6.zip
Simplify initialization of HWPF EscherRecordHolder
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886999 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java6
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/model/EscherRecordHolder.java17
2 files changed, 12 insertions, 11 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
index 3bd96bf206..3e1de7c0a7 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
@@ -309,11 +309,7 @@ public final class HWPFDocument extends HWPFDocumentCore {
FSPADocumentPart.HEADER);
_fspaMain = new FSPATable(_tableStream, _fib, FSPADocumentPart.MAIN);
- if (_fib.getFcDggInfo() != 0) {
- _escherRecordHolder = new EscherRecordHolder(_tableStream, _fib.getFcDggInfo(), _fib.getLcbDggInfo());
- } else {
- _escherRecordHolder = new EscherRecordHolder();
- }
+ _escherRecordHolder = new EscherRecordHolder(_tableStream, _fib.getFcDggInfo(), _fib.getLcbDggInfo());
// read in the pictures stream
_pictures = new PicturesTable(this, _dataStream, _mainStream, _fspaMain, _escherRecordHolder);
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/EscherRecordHolder.java b/src/scratchpad/src/org/apache/poi/hwpf/model/EscherRecordHolder.java
index df62b420ad..ccc0a7e42c 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/model/EscherRecordHolder.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/model/EscherRecordHolder.java
@@ -34,19 +34,23 @@ import org.apache.poi.util.Internal;
*/
@Internal
public final class EscherRecordHolder {
- private final ArrayList<EscherRecord> escherRecords;
-
- public EscherRecordHolder() {
- escherRecords = new ArrayList<>();
- }
+ private final ArrayList<EscherRecord> escherRecords = new ArrayList<>();
public EscherRecordHolder(byte[] data, int offset, int size) {
- this();
fillEscherRecords(data, offset, size);
}
+ /**
+ * Parses the records out of the given data.
+ *
+ * The thing to be aware of here is that if {@code size} is {@code 0}, the document does not contain images.
+ *
+ * @see FileInformationBlock#getLcbDggInfo()
+ */
private void fillEscherRecords(byte[] data, int offset, int size)
{
+ if (size == 0) return;
+
EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
int pos = offset;
while ( pos < offset + size)
@@ -62,6 +66,7 @@ public final class EscherRecordHolder {
return escherRecords;
}
+ @Override
public String toString() {
StringBuilder buffer = new StringBuilder();