From b7038df14dc09a640d4c4d67820dba98f09cf7f6 Mon Sep 17 00:00:00 2001 From: Marius Volkhart Date: Sun, 28 Feb 2021 16:47:43 +0000 Subject: Simplify initialization of HWPF EscherRecordHolder git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886999 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/org/apache/poi/hwpf/HWPFDocument.java | 6 +----- .../org/apache/poi/hwpf/model/EscherRecordHolder.java | 17 +++++++++++------ 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 escherRecords; - - public EscherRecordHolder() { - escherRecords = new ArrayList<>(); - } + private final ArrayList 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(); -- cgit v1.2.3