diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2020-01-26 19:50:40 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2020-01-26 19:50:40 +0000 |
commit | 8202a34d6956c6d81f94a194b8b94eb716efbaa6 (patch) | |
tree | 3aaeb16e3d195e07696fe5c0a4002902bedeca11 /src/scratchpad | |
parent | 563c29f8cf6bb7a488826c37cbea3a22d5bfaed5 (diff) | |
download | poi-8202a34d6956c6d81f94a194b8b94eb716efbaa6.tar.gz poi-8202a34d6956c6d81f94a194b8b94eb716efbaa6.zip |
#64036 - Replace reflection calls in factories for Java 9+ - Escher factories
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1873187 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad')
-rw-r--r-- | src/scratchpad/src/org/apache/poi/hslf/record/HSLFEscherRecordFactory.java | 41 |
1 files changed, 11 insertions, 30 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/HSLFEscherRecordFactory.java b/src/scratchpad/src/org/apache/poi/hslf/record/HSLFEscherRecordFactory.java index e9eb2b1479..416022e7a9 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/HSLFEscherRecordFactory.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/HSLFEscherRecordFactory.java @@ -17,11 +17,11 @@ package org.apache.poi.hslf.record; -import java.lang.reflect.Constructor; -import java.util.Map; +import java.util.function.Supplier; -import org.apache.poi.ddf.*; -import org.apache.poi.util.LittleEndian; +import org.apache.poi.ddf.DefaultEscherRecordFactory; +import org.apache.poi.ddf.EscherRecord; +import org.apache.poi.ddf.EscherRecordFactory; /** * Generates escher records when provided the byte array containing those records. @@ -29,39 +29,20 @@ import org.apache.poi.util.LittleEndian; * @see EscherRecordFactory */ public class HSLFEscherRecordFactory extends DefaultEscherRecordFactory { - private static Class<?>[] escherRecordClasses = { EscherPlaceholder.class, HSLFEscherClientDataRecord.class }; - private static Map<Short, Constructor<? extends EscherRecord>> recordsMap = recordsToMap( escherRecordClasses ); - - /** * Creates an instance of the escher record factory */ public HSLFEscherRecordFactory() { // no instance initialisation } - - @Override - public EscherRecord createRecord(byte[] data, int offset) { - short options = LittleEndian.getShort( data, offset ); - short recordId = LittleEndian.getShort( data, offset + 2 ); - // int remainingBytes = LittleEndian.getInt( data, offset + 4 ); - Constructor<? extends EscherRecord> recordConstructor = recordsMap.get(Short.valueOf(recordId)); - if (recordConstructor == null) { - return super.createRecord(data, offset); - } - EscherRecord escherRecord = null; - try { - escherRecord = recordConstructor.newInstance(new Object[] {}); - } catch (Exception e) { - return super.createRecord(data, offset); - } - escherRecord.setRecordId(recordId); - escherRecord.setOptions(options); - if (escherRecord instanceof EscherContainerRecord) { - escherRecord.fillFields(data, offset, this); + @Override + protected Supplier<? extends EscherRecord> getConstructor(short options, short recordId) { + if (recordId == EscherPlaceholder.RECORD_ID) { + return EscherPlaceholder::new; + } else if (recordId == HSLFEscherClientDataRecord.RECORD_ID) { + return HSLFEscherClientDataRecord::new; } - - return escherRecord; + return super.getConstructor(options, recordId); } } |