]> source.dussan.org Git - poi.git/commitdiff
fix IntelliJ warnings
authorAndreas Beeker <kiwiwings@apache.org>
Fri, 21 Feb 2020 21:14:31 +0000 (21:14 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Fri, 21 Feb 2020 21:14:31 +0000 (21:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1874338 13f79535-47bb-0310-9956-ffa450edef68

22 files changed:
src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java
src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfDraw.java
src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFill.java
src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFont.java
src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfHeader.java
src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfMisc.java
src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfPalette.java
src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfRecord.java
src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfText.java
src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfWindowing.java
src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java
src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusDraw.java
src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusGDIImageRenderer.java
src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusHeader.java
src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusImage.java
src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusMisc.java
src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java
src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusPath.java
src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusPen.java
src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusRecord.java
src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusRegion.java
src/scratchpad/src/org/apache/poi/hemf/record/emfplus/UnimplementedHemfPlusRecord.java

index d476c21bcc0e567c9c7212a6ac75328890b1c589..2e603fe261448a3874cc2efe8790b81deff82b3e 100644 (file)
@@ -96,10 +96,10 @@ public class HemfComment {
          *
          * @param ctx the graphics context to modify
          */
-        default void draw(HemfGraphics ctx) {};
+        default void draw(HemfGraphics ctx) {}
 
         @Override
-        default Enum getGenericRecordType() {
+        default HemfCommentRecordType getGenericRecordType() {
             return getCommentRecordType();
         }
     }
@@ -137,6 +137,14 @@ public class HemfComment {
         public Map<String, Supplier<?>> getGenericProperties() {
             return GenericRecordUtil.getGenericProperties("data", this::getCommentData);
         }
+
+        static void validateCommentType(final LittleEndianInputStream leis, HemfCommentRecordType commentType) {
+            int commentIdentifier = (int)leis.readUInt();
+            if (commentIdentifier == HemfCommentRecordType.emfPublic.id) {
+                commentIdentifier = (int)leis.readUInt();
+            }
+            assert(commentIdentifier == commentType.id);
+        }
     }
 
     public static class EmfCommentDataIterator implements Iterator<EmfCommentData> {
@@ -172,20 +180,19 @@ public class HemfComment {
         }
 
         private EmfCommentData _next() {
-            long type, recordSize;
+            long recordSize;
             if (currentRecord == null && emfParent) {
-                type = HemfRecordType.comment.id;
                 recordSize = limit;
             } else {
                 // A 32-bit unsigned integer from the RecordType enumeration that identifies this record
                 // as a comment record. This value MUST be 0x00000046.
                 try {
-                    type = leis.readUInt();
+                    long type = leis.readUInt();
+                    assert(type == HemfRecordType.comment.id);
                 } catch (RuntimeException e) {
                     // EOF
                     return null;
                 }
-                assert(type == HemfRecordType.comment.id);
                 // A 32-bit unsigned integer that specifies the size in bytes of this record in the
                 // metafile. This value MUST be a multiple of 4 bytes.
                 recordSize = leis.readUInt();
@@ -288,9 +295,8 @@ public class HemfComment {
         @Override
         public long init(final LittleEndianInputStream leis, final long dataSize)
         throws IOException {
-            long startIdx = leis.getReadIndex();
-            int commentIdentifier = leis.readInt();
-            assert (commentIdentifier == HemfCommentRecordType.emfPlus.id);
+            final int startIdx = leis.getReadIndex();
+            EmfComment.validateCommentType(leis, HemfCommentRecordType.emfPlus);
             new HemfPlusRecordIterator(leis, (int)dataSize-LittleEndianConsts.INT_SIZE).forEachRemaining(records::add);
             return leis.getReadIndex()-startIdx;
         }
@@ -328,13 +334,9 @@ public class HemfComment {
         }
 
         @Override
-        public long init(final LittleEndianInputStream leis, final long dataSize)
-        throws IOException {
+        public long init(final LittleEndianInputStream leis, final long dataSize) throws IOException {
             final int startIdx = leis.getReadIndex();
-            final int commentIdentifier = (int)leis.readUInt();
-            assert(commentIdentifier == HemfCommentRecordType.emfPublic.id);
-            final int publicCommentIdentifier = (int)leis.readUInt();
-            assert(publicCommentIdentifier == HemfCommentRecordType.emfBeginGroup.id);
+            EmfComment.validateCommentType(leis, HemfCommentRecordType.emfBeginGroup);
             HemfDraw.readRectL(leis, bounds);
 
             // The number of Unicode characters in the optional description string that follows.
@@ -347,6 +349,7 @@ public class HemfComment {
             return leis.getReadIndex()-startIdx;
         }
 
+
         public Rectangle2D getBounds() {
             return bounds;
         }
@@ -374,10 +377,7 @@ public class HemfComment {
         public long init(final LittleEndianInputStream leis, final long dataSize)
         throws IOException {
             final int startIdx = leis.getReadIndex();
-            final int commentIdentifier = (int)leis.readUInt();
-            assert(commentIdentifier == HemfCommentRecordType.emfPublic.id);
-            final int publicCommentIdentifier = (int)leis.readUInt();
-            assert(publicCommentIdentifier == HemfCommentRecordType.emfEndGroup.id);
+            EmfComment.validateCommentType(leis, HemfCommentRecordType.emfEndGroup);
             return leis.getReadIndex()-startIdx;
         }
 
@@ -397,13 +397,9 @@ public class HemfComment {
         }
 
         @Override
-        public long init(final LittleEndianInputStream leis, final long dataSize)
-                throws IOException {
+        public long init(final LittleEndianInputStream leis, final long dataSize) throws IOException {
             final int startIdx = leis.getReadIndex();
-            final int commentIdentifier = (int)leis.readUInt();
-            assert(commentIdentifier == HemfCommentRecordType.emfPublic.id);
-            final int publicCommentIdentifier = (int)leis.readUInt();
-            assert(publicCommentIdentifier == HemfCommentRecordType.emfMultiFormats.id);
+            EmfComment.validateCommentType(leis, HemfCommentRecordType.emfMultiFormats);
             HemfDraw.readRectL(leis, bounds);
 
             // A 32-bit unsigned integer that specifies the number of graphics formats contained in this record.
@@ -487,6 +483,7 @@ public class HemfComment {
         private int offData;
         private byte[] rawData;
 
+        @SuppressWarnings("unused")
         public long init(final LittleEndianInputStream leis, final long dataSize, long startIdx) throws IOException {
             // A 32-bit unsigned integer that specifies the format of the image data.
             signature = EmfFormatSignature.getById(leis.readInt());
@@ -539,13 +536,11 @@ public class HemfComment {
             return HemfCommentRecordType.emfWMF;
         }
 
+        @SuppressWarnings("unused")
         @Override
         public long init(final LittleEndianInputStream leis, final long dataSize) throws IOException {
             final int startIdx = leis.getReadIndex();
-            final int commentIdentifier = (int)leis.readUInt();
-            assert(commentIdentifier == HemfCommentRecordType.emfPublic.id);
-            final int publicCommentIdentifier = (int)leis.readUInt();
-            assert(publicCommentIdentifier == HemfCommentRecordType.emfWMF.id);
+            EmfComment.validateCommentType(leis, HemfCommentRecordType.emfWMF);
 
             // A 16-bit unsigned integer that specifies the WMF metafile version in terms
             //of support for device-independent bitmaps (DIBs)
index 71a2dad577b8d42a2daacd2129826102a65e7675..caabb04a4c9989e542d16127dd73fb04e80cfcc9 100644 (file)
@@ -42,7 +42,9 @@ import org.apache.poi.util.GenericRecordUtil;
 import org.apache.poi.util.LittleEndianConsts;
 import org.apache.poi.util.LittleEndianInputStream;
 
-public class HemfDraw {
+public final class HemfDraw {
+    private HemfDraw() {}
+
     /**
      * The EMR_SELECTOBJECT record adds a graphics object to the current metafile playback device
      * context. The object is specified either by its index in the EMF Object Table or by its
@@ -102,7 +104,7 @@ public class HemfDraw {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -212,7 +214,7 @@ public class HemfDraw {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -313,7 +315,7 @@ public class HemfDraw {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -456,6 +458,7 @@ public class HemfDraw {
             return readPointL(leis, point);
         }
 
+        @SuppressWarnings("unused")
         @Override
         public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
             long size = readRectL(leis, bounds);
@@ -521,7 +524,7 @@ public class HemfDraw {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -593,7 +596,7 @@ public class HemfDraw {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -618,7 +621,7 @@ public class HemfDraw {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -647,7 +650,7 @@ public class HemfDraw {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -677,7 +680,7 @@ public class HemfDraw {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -706,7 +709,7 @@ public class HemfDraw {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -733,7 +736,7 @@ public class HemfDraw {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -759,7 +762,7 @@ public class HemfDraw {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -792,7 +795,7 @@ public class HemfDraw {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -818,7 +821,7 @@ public class HemfDraw {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -848,7 +851,7 @@ public class HemfDraw {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -958,7 +961,7 @@ public class HemfDraw {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -1215,8 +1218,6 @@ public class HemfDraw {
      * path by using the current pen, and fills its interior by using the current brush.
      */
     public static class EmfStrokeAndFillPath extends EmfStrokePath {
-        protected final Rectangle2D bounds = new Rectangle2D.Double();
-
         @Override
         public HemfRecordType getEmfRecordType() {
             return HemfRecordType.strokeAndFillPath;
index d6b8228ea6a85d22f956ad537497b94637f3447f..195182a5097ded604f331b50f4aaae9d2a6aa794 100644 (file)
@@ -53,8 +53,8 @@ import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.LittleEndianConsts;
 import org.apache.poi.util.LittleEndianInputStream;
 
-public class HemfFill {
-    private static final int MAX_RECORD_LENGTH = 10_000_000;
+public final class HemfFill {
+    private HemfFill() {}
 
     /**
      * The EMR_SETPOLYFILLMODE record defines polygon fill mode.
@@ -75,7 +75,7 @@ public class HemfFill {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -98,7 +98,7 @@ public class HemfFill {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -224,7 +224,7 @@ public class HemfFill {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -309,7 +309,7 @@ public class HemfFill {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -341,6 +341,7 @@ public class HemfFill {
             return HemfRecordType.frameRgn;
         }
 
+        @SuppressWarnings("unused")
         @Override
         public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
             long size = readRectL(leis, bounds);
@@ -386,7 +387,7 @@ public class HemfFill {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -401,6 +402,7 @@ public class HemfFill {
             return HemfRecordType.invertRgn;
         }
 
+        @SuppressWarnings("unused")
         @Override
         public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
             long size = readRectL(leis, bounds);
@@ -453,6 +455,7 @@ public class HemfFill {
             return HemfRecordType.fillRgn;
         }
 
+        @SuppressWarnings("unused")
         @Override
         public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
             long size = readRectL(leis, bounds);
@@ -486,7 +489,7 @@ public class HemfFill {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -500,6 +503,7 @@ public class HemfFill {
             return HemfRecordType.extSelectClipRgn;
         }
 
+        @SuppressWarnings("unused")
         @Override
         public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
             // A 32-bit unsigned integer that specifies the size of region data in bytes
@@ -522,7 +526,6 @@ public class HemfFill {
 
         @Override
         public void draw(HemfGraphics ctx) {
-            HemfDrawProperties prop = ctx.getProperties();
             ctx.setClip(getShape(), regionMode, true);
         }
 
@@ -692,6 +695,7 @@ public class HemfFill {
             return HemfRecordType.setDiBitsToDevice;
         }
 
+        @SuppressWarnings("unused")
         @Override
         public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
             int startIdx = leis.getReadIndex();
@@ -804,6 +808,7 @@ public class HemfFill {
     }
 
 
+    @SuppressWarnings("unused")
     static long readRgnData(final LittleEndianInputStream leis, final List<Rectangle2D> rgnRects) {
         // *** RegionDataHeader ***
         // A 32-bit unsigned integer that specifies the size of this object in bytes. This MUST be 0x00000020.
@@ -873,7 +878,7 @@ public class HemfFill {
         return 6 * LittleEndian.INT_SIZE;
     }
 
-    protected static Shape getRgnShape(List<Rectangle2D> rgnRects) {
+    static Shape getRgnShape(List<Rectangle2D> rgnRects) {
         if (rgnRects.size() == 1) {
             return rgnRects.get(0);
         }
index 66229fb536a7a66718c019a79f829e9658ddb809..b95f83c3cffd534af848dadb56eb59111b845ad4 100644 (file)
@@ -237,6 +237,7 @@ public class HemfFont extends HwmfFont {
 
     protected LogFontDetails details;
 
+    @SuppressWarnings("unused")
     @Override
     public int init(LittleEndianInputStream leis, long recordSize) throws IOException {
         // A 32-bit signed integer that specifies the height, in logical units, of the font's
@@ -517,7 +518,7 @@ public class HemfFont extends HwmfFont {
     }
 
     @Override
-    protected int readString(LittleEndianInputStream leis, StringBuilder sb, int limit) throws IOException {
+    protected int readString(LittleEndianInputStream leis, StringBuilder sb, int limit) {
         sb.setLength(0);
         byte[] buf = new byte[limit * 2];
         leis.readFully(buf);
index 52a405502961d776e55b3167a8cde0533c7af6f7..d8d3d34c7c1fba24cefd58928b00936d7e98a859 100644 (file)
@@ -43,9 +43,6 @@ import org.apache.poi.util.LittleEndianInputStream;
 @Internal
 public class HemfHeader implements HemfRecord {
 
-    private static final int MAX_RECORD_LENGTH = 1_000_000;
-
-
     private final Rectangle2D boundsRectangle = new Rectangle2D.Double();
     private final Rectangle2D frameRectangle = new Rectangle2D.Double();
     private long bytes;
@@ -131,6 +128,7 @@ public class HemfHeader implements HemfRecord {
         return HemfRecordType.header;
     }
 
+    @SuppressWarnings("unused")
     @Override
     public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
         if (recordId != HemfRecordType.header.id) {
index e9056f682c25962a4fb5814c3d39a776aa6d98ce..4552f858a20a687c2f829636efbeab9409cc243a 100644 (file)
@@ -100,6 +100,7 @@ public class HemfMisc {
             return HemfRecordType.eof;
         }
 
+        @SuppressWarnings("unused")
         @Override
         public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
             final int startIdx = leis.getReadIndex();
@@ -112,7 +113,7 @@ public class HemfMisc {
             int size = 2 * LittleEndianConsts.INT_SIZE;
 
             if (nPalEntries > 0 && offPalEntries > 0) {
-                int undefinedSpace1 = (int) (offPalEntries - (size + HEADER_SIZE));
+                int undefinedSpace1 = offPalEntries - (size + HEADER_SIZE);
                 assert (undefinedSpace1 >= 0);
                 leis.skipFully(undefinedSpace1);
                 size += undefinedSpace1;
@@ -165,7 +166,7 @@ public class HemfMisc {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -191,7 +192,7 @@ public class HemfMisc {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -213,7 +214,7 @@ public class HemfMisc {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -240,7 +241,7 @@ public class HemfMisc {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -260,7 +261,7 @@ public class HemfMisc {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -283,7 +284,7 @@ public class HemfMisc {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -306,7 +307,7 @@ public class HemfMisc {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -331,7 +332,7 @@ public class HemfMisc {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -385,7 +386,7 @@ public class HemfMisc {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -454,7 +455,7 @@ public class HemfMisc {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -477,7 +478,7 @@ public class HemfMisc {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -538,7 +539,7 @@ public class HemfMisc {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -668,7 +669,7 @@ public class HemfMisc {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
index 5c5f9283ac175d9f520469322c0da5c96c3d831c..0bfbebad38824a81d80d488a5e4fbd87da7cc4d8 100644 (file)
@@ -48,7 +48,7 @@ public class HemfPalette {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -96,7 +96,7 @@ public class HemfPalette {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -144,7 +144,7 @@ public class HemfPalette {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -191,7 +191,7 @@ public class HemfPalette {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -212,7 +212,7 @@ public class HemfPalette {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
index cd33b10ca0812cbbce585c78cc45ac1bdbbefec2..0ab50e819dfe3f344fb602226f6d03cb81e0c6b1 100644 (file)
@@ -63,7 +63,7 @@ public interface HemfRecord extends GenericRecord {
     default void setHeader(HemfHeader header) {}
 
     @Override
-    default Enum getGenericRecordType() {
+    default HemfRecordType getGenericRecordType() {
         return getEmfRecordType();
     }
 }
index 3c8e906e1096ab87b862896cadc40a3e6a9f3bbc..344cc62a9b5d1f81d9b4947e681c3647139461e6 100644 (file)
@@ -225,7 +225,7 @@ public class HemfText {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -266,7 +266,7 @@ public class HemfText {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -286,7 +286,7 @@ public class HemfText {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -338,7 +338,7 @@ public class HemfText {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
index d95b9d94a030669bd324f2220322a9550b1a7b6f..6167cd6028606ff69ab5a19bba3392e55f41b433 100644 (file)
@@ -53,7 +53,7 @@ public class HemfWindowing {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -73,7 +73,7 @@ public class HemfWindowing {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -93,7 +93,7 @@ public class HemfWindowing {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -113,7 +113,7 @@ public class HemfWindowing {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -134,7 +134,7 @@ public class HemfWindowing {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -155,7 +155,7 @@ public class HemfWindowing {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -176,7 +176,7 @@ public class HemfWindowing {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -197,7 +197,7 @@ public class HemfWindowing {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
@@ -218,7 +218,7 @@ public class HemfWindowing {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public HemfRecordType getGenericRecordType() {
             return getEmfRecordType();
         }
     }
index 4aeaf43e94e82161c40b92f352fa7f56f49aed2b..e297bd45d13e5c8a6e902d2d068daf0a520a2883 100644 (file)
@@ -251,6 +251,7 @@ public class HemfPlusBrush {
 
     }
 
+    @SuppressWarnings("unused")
     public interface EmfPlusBrushData extends GenericRecord {
         /**
          * This flag is meaningful in EmfPlusPathGradientBrushData objects.
@@ -458,7 +459,7 @@ public class HemfPlusBrush {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public EmfPlusBrushType getGenericRecordType() {
             return EmfPlusBrushType.SOLID_COLOR;
         }
 
@@ -500,7 +501,7 @@ public class HemfPlusBrush {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public EmfPlusBrushType getGenericRecordType() {
             return EmfPlusBrushType.HATCH_FILL;
         }
 
@@ -600,7 +601,7 @@ public class HemfPlusBrush {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public EmfPlusBrushType getGenericRecordType() {
             return EmfPlusBrushType.LINEAR_GRADIENT;
         }
 
@@ -810,7 +811,7 @@ public class HemfPlusBrush {
 
 
         @Override
-        public Enum getGenericRecordType() {
+        public EmfPlusBrushType getGenericRecordType() {
             return EmfPlusBrushType.PATH_GRADIENT;
         }
 
@@ -884,7 +885,7 @@ public class HemfPlusBrush {
         }
 
         @Override
-        public Enum getGenericRecordType() {
+        public EmfPlusBrushType getGenericRecordType() {
             return EmfPlusBrushType.TEXTURE_FILL;
         }
 
index 09b51fd1d28bbee4e7c1bd9a8c4229a08ff4119b..92e58f58f1f7146545337a1a3a6927ca737cdb40 100644 (file)
@@ -62,9 +62,11 @@ import org.apache.poi.util.LittleEndianInputStream;
 import org.apache.poi.util.StringUtil;
 
 @SuppressWarnings("WeakerAccess")
-public class HemfPlusDraw {
+public final class HemfPlusDraw {
     private static final int MAX_OBJECT_SIZE = 1_000_000;
 
+    private HemfPlusDraw() {}
+
     public enum EmfPlusUnitType {
         /** Specifies a unit of logical distance within the world space. */
         World(0x00),
@@ -126,9 +128,9 @@ public class HemfPlusDraw {
          * If set, each element in PointData specifies a location in the coordinate space that is relative to the
          * location specified by the previous element in the array. In the case of the first element in PointData,
          * a previous location at coordinates (0,0) is assumed.
-         * If clear, PointData specifies absolute locations according to the {@link #isCompressed()} flag.
+         * If clear, PointData specifies absolute locations according to the {@link EmfPlusCompressed#isCompressed()} flag.
          *
-         * Note If this flag is set, the {@link #isCompressed()} flag (above) is undefined and MUST be ignored.
+         * Note If this flag is set, the {@link EmfPlusCompressed#isCompressed()} flag (above) is undefined and MUST be ignored.
          */
         BitField POSITION = BitFieldFactory.getInstance(0x0800);
 
@@ -330,6 +332,7 @@ public class HemfPlusDraw {
     }
 
     /** The EmfPlusDrawImagePoints record specifies drawing a scaled image inside a parallelogram. */
+    @SuppressWarnings("unused")
     public static class EmfPlusDrawImagePoints implements HemfPlusRecord, EmfPlusObjectId, EmfPlusCompressed, EmfPlusRelativePosition {
         /**
          * This bit indicates that the rendering of the image includes applying an effect.
@@ -625,6 +628,7 @@ public class HemfPlusDraw {
     }
 
     /** The EmfPlusDrawDriverString record specifies text output with character positions. */
+    @SuppressWarnings("unused")
     public static class EmfPlusDrawDriverString implements HemfPlusRecord, EmfPlusObjectId, EmfPlusSolidColor {
         /**
          * If set, the positions of character glyphs SHOULD be specified in a character map lookup table.
index 251dd412007f16e19b449e587e374bc233767fc5..2d8f3b0e4529e266e871e61e0e84fcc4858a216b 100644 (file)
@@ -32,6 +32,7 @@ import java.io.InputStream;
 import org.apache.poi.sl.draw.BitmapImageRenderer;
 import org.apache.poi.util.IOUtils;
 
+@SuppressWarnings("unused")
 public class HemfPlusGDIImageRenderer extends BitmapImageRenderer {
     private int width;
     private int height;
@@ -81,7 +82,7 @@ public class HemfPlusGDIImageRenderer extends BitmapImageRenderer {
     }
 
     @Override
-    public void loadImage(byte[] data, String contentType) throws IOException {
+    public void loadImage(byte[] data, String contentType) {
         img = readGDIImage(data);
     }
 
index 256c72ea49d5010507b3f944edcb8a3a30f79a24..e61dae8d2fc0961efeea72ce36e4ba5f586a1638 100644 (file)
@@ -110,6 +110,7 @@ public class HemfPlusHeader implements HemfPlusRecord {
      *
      * @return {@code true} if dual-mode is enabled
      */
+    @SuppressWarnings("unused")
     public boolean isEmfPlusDualMode() {
         return (flags & 1) == 1;
     }
index d8ad091f2fbd7035114d6da48b3dba017a999343..840b752f378b3fa9d47666267fb0017f31b64ba9 100644 (file)
@@ -52,9 +52,6 @@ import org.apache.poi.util.LittleEndianConsts;
 import org.apache.poi.util.LittleEndianInputStream;
 
 public class HemfPlusImage {
-    /** Maximum image dimension for converting embedded metafiles */
-    private static final int MAX_IMAGE_SIZE = 1500;
-
     /** The ImageDataType enumeration defines types of image data formats. */
     public enum EmfPlusImageDataType {
         /** The type of image is not known. */
@@ -80,6 +77,7 @@ public class HemfPlusImage {
         }
     }
 
+    @SuppressWarnings("unused")
     public enum EmfPlusPixelFormat {
         UNDEFINED(0X00000000),
         INDEXED_1BPP(0X00030101),
index 2a8866be4867efd17612166fc6621ad2c5ed7032..40b3d729ebfcd3796f9975eece61625d3c1ccc4d 100644 (file)
@@ -243,8 +243,6 @@ public class HemfPlusMisc {
 
         @Override
         public void draw(HemfGraphics ctx) {
-            HemfDrawProperties prop = ctx.getProperties();
-
             AffineTransform tx = ctx.getInitTransform();
             tx.concatenate(getMatrixData());
             ctx.setTransform(tx);
@@ -318,6 +316,7 @@ public class HemfPlusMisc {
     }
 
     /** The EmfPlusSetClipRect record combines the current clipping region with a rectangle. */
+    @SuppressWarnings("unused")
     public static class EmfPlusSetClipRect implements HemfPlusRecord {
         private static final BitField COMBINE_MODE = BitFieldFactory.getInstance(0x0F00);
 
index 06335f0ad01abf7e6a77303b2f146c28f1493432..908a1d11510c8e241ffe24e13ff43dab5df41896 100644 (file)
@@ -117,6 +117,7 @@ public class HemfPlusObject {
      * The EmfPlusObject record specifies an object for use in graphics operations. The object definition
      * can span multiple records), which is indicated by the value of the Flags field.
      */
+    @SuppressWarnings("unused")
     public static class EmfPlusObject implements HemfPlusRecord, EmfPlusObjectId, HwmfObjectTableEntry {
         /**
          * Indicates that the object definition continues on in the next EmfPlusObject
@@ -136,6 +137,7 @@ public class HemfPlusObject {
 
         private int flags;
         // for debugging
+        @SuppressWarnings("FieldCanBeLocal")
         private int objectId;
         private EmfPlusObjectData objectData;
         private List<EmfPlusObjectData> continuedObjectData;
@@ -155,6 +157,7 @@ public class HemfPlusObject {
             return EmfPlusObjectType.valueOf(OBJECT_TYPE.getValue(flags));
         }
 
+        @SuppressWarnings("unchecked")
         public <T extends EmfPlusObjectData> T getObjectData() {
             return (T)objectData;
         }
index ef29a9d63d24bac338628845440e4e211804d80a..a69f4954e10f0dd3a416a96fc841f131726f73e0 100644 (file)
@@ -55,9 +55,10 @@ public class HemfPlusPath {
         // not defined
         UNUSED,
         /** Specifies that the point is an endpoint or control point of a cubic Bezier curve */
-        BEZIER;
+        BEZIER
     }
 
+    @SuppressWarnings("unused")
     public static class EmfPlusPath implements EmfPlusObjectData, EmfPlusCompressed, EmfPlusRelativePosition {
         /**
          * If set, the point types in the PathPointTypes array are specified by EmfPlusPathPointTypeRLE objects,
index a52841bb56d180f8ecdeae90b4b038575d12af7a..b2213df7072c5e82d34de3d84d34d13efb87e216 100644 (file)
@@ -46,6 +46,7 @@ import org.apache.poi.hwmf.record.HwmfPenStyle.HwmfLineDash;
 import org.apache.poi.hwmf.record.HwmfPenStyle.HwmfLineJoin;
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
+import org.apache.poi.util.GenericRecordUtil;
 import org.apache.poi.util.Internal;
 import org.apache.poi.util.LittleEndianConsts;
 import org.apache.poi.util.LittleEndianInputStream;
@@ -233,14 +234,64 @@ public class HemfPlusPen {
 
 
     @Internal
-    public interface EmfPlusCustomLineCap extends GenericRecord {
-        long init(LittleEndianInputStream leis) throws IOException;
-    }
+    public static abstract class EmfPlusCustomLineCap implements GenericRecord {
+        private EmfPlusLineCapType startCap;
+        private EmfPlusLineCapType endCap;
+        private EmfPlusLineJoin join;
+        private double miterLimit;
+        private double widthScale;
+        private final Point2D fillHotSpot = new Point2D.Double();
+        private final Point2D lineHotSpot = new Point2D.Double();
 
+        protected long init(LittleEndianInputStream leis) throws IOException {
+            // A 32-bit unsigned integer that specifies the value in the LineCap enumeration that indicates the line
+            // cap used at the start/end of the line to be drawn.
+            startCap = EmfPlusLineCapType.valueOf(leis.readInt());
+            endCap = EmfPlusLineCapType.valueOf(leis.readInt());
 
-    public static class EmfPlusPen implements EmfPlusObjectData {
+            // A 32-bit unsigned integer that specifies the value in the LineJoin enumeration, which specifies how
+            // to join two lines that are drawn by the same pen and whose ends meet. At the intersection of the two
+            // line ends, a line join makes the connection look more continuous.
+            join = EmfPlusLineJoin.valueOf(leis.readInt());
+
+            // A 32-bit floating-point value that contains the limit of the thickness of the join on a mitered corner
+            // by setting the maximum allowed ratio of miter length to line width.
+            miterLimit = leis.readFloat();
+
+            // A 32-bit floating-point value that specifies the amount by which to scale the custom line cap with
+            // respect to the width of the EmfPlusPen object that is used to draw the lines.
+            widthScale = leis.readFloat();
+
+            long size = 5*LittleEndianConsts.INT_SIZE;
+
+            // An EmfPlusPointF object that is not currently used. It MUST be set to {0.0, 0.0}.
+            size += readPointF(leis, fillHotSpot);
+            size += readPointF(leis, lineHotSpot);
+
+            return size;
+        }
+
+        @Override
+        public Map<String, Supplier<?>> getGenericProperties() {
+            final Map<String,Supplier<?>> m = new LinkedHashMap<>();
+            m.put("startCap", () -> startCap);
+            m.put("endCap", () -> endCap);
+            m.put("join", () -> join);
+            m.put("miterLimit", () -> miterLimit);
+            m.put("widthScale", () -> widthScale);
+            m.put("fillHotSpot", () -> fillHotSpot);
+            m.put("lineHotSpot", () -> lineHotSpot);
+            return m;
+        }
+
+        @Override
+        public final EmfPlusObjectType getGenericRecordType() {
+            return EmfPlusObjectType.CUSTOM_LINE_CAP;
+        }
+    }
 
 
+    public static class EmfPlusPen implements EmfPlusObjectData {
         /**
          * If set, a 2x3 transform matrix MUST be specified in the OptionalData field of an EmfPlusPenData object.
          */
@@ -581,7 +632,7 @@ public class HemfPlusPen {
         }
     }
 
-    public static class EmfPlusPathArrowCap implements EmfPlusCustomLineCap {
+    public static class EmfPlusPathArrowCap extends EmfPlusCustomLineCap {
         /**
          * If set, an EmfPlusFillPath object MUST be specified in the OptionalData field of the
          * EmfPlusCustomLineCapData object for filling the custom line cap.
@@ -600,13 +651,6 @@ public class HemfPlusPen {
         private int dataFlags;
         private EmfPlusLineCapType baseCap;
         private double baseInset;
-        private EmfPlusLineCapType startCap;
-        private EmfPlusLineCapType endCap;
-        private EmfPlusLineJoin join;
-        private double miterLimit;
-        private double widthScale;
-        private final Point2D fillHotSpot = new Point2D.Double();
-        private final Point2D lineHotSpot = new Point2D.Double();
         private EmfPlusPath fillPath;
         private EmfPlusPath outlinePath;
 
@@ -624,78 +668,44 @@ public class HemfPlusPen {
             // beginning of the line cap and the end of the line.
             baseInset = leis.readFloat();
 
-            // A 32-bit unsigned integer that specifies the value in the LineCap enumeration that indicates the line
-            // cap used at the start/end of the line to be drawn.
-            startCap = EmfPlusLineCapType.valueOf(leis.readInt());
-            endCap = EmfPlusLineCapType.valueOf(leis.readInt());
+            long size = 3*LittleEndianConsts.INT_SIZE;
 
-            // A 32-bit unsigned integer that specifies the value in the LineJoin enumeration, which specifies how
-            // to join two lines that are drawn by the same pen and whose ends meet. At the intersection of the two
-            // line ends, a line join makes the connection look more continuous.
-            join = EmfPlusLineJoin.valueOf(leis.readInt());
-
-            // A 32-bit floating-point value that contains the limit of the thickness of the join on a mitered corner
-            // by setting the maximum allowed ratio of miter length to line width.
-            miterLimit = leis.readFloat();
-
-            // A 32-bit floating-point value that specifies the amount by which to scale the custom line cap with
-            // respect to the width of the EmfPlusPen object that is used to draw the lines.
-            widthScale = leis.readFloat();
-
-            int size = 8* LittleEndianConsts.INT_SIZE;
+            size += super.init(leis);
 
-            // An EmfPlusPointF object that is not currently used. It MUST be set to {0.0, 0.0}.
-            size += readPointF(leis, fillHotSpot);
-            size += readPointF(leis, lineHotSpot);
+            size += initPath(leis, FILL_PATH, p -> fillPath = p);
+            size += initPath(leis, LINE_PATH, p -> outlinePath = p);
 
-            if (FILL_PATH.isSet(dataFlags)) {
-                int fillSize = leis.readInt();
-                size += LittleEndianConsts.INT_SIZE;
-                fillPath = new EmfPlusPath();
-                size += fillPath.init(leis, fillSize, EmfPlusObjectType.PATH, -1);
-            }
+            return size;
+        }
 
-            if (LINE_PATH.isSet(dataFlags)) {
-                int pathSize = leis.readInt();
-                size += LittleEndianConsts.INT_SIZE;
-                outlinePath = new EmfPlusPath();
-                size += outlinePath.init(leis, pathSize, EmfPlusObjectType.PATH, -1);
+        private long initPath(LittleEndianInputStream leis, BitField bitField, Consumer<EmfPlusPath> setter) throws IOException {
+            if (!bitField.isSet(dataFlags)) {
+                return 0;
             }
-
-            return size;
+            int pathSize = leis.readInt();
+            EmfPlusPath path = new EmfPlusPath();
+            setter.accept(path);
+            return LittleEndianConsts.INT_SIZE + path.init(leis, pathSize, EmfPlusObjectType.PATH, -1);
         }
 
         @Override
         public Map<String, Supplier<?>> getGenericProperties() {
-            final Map<String,Supplier<?>> m = new LinkedHashMap<>();
-            m.put("flags", getBitsAsString(() -> dataFlags, FLAGS_MASKS, FLAGS_NAMES));
-            m.put("baseCap", () -> baseCap);
-            m.put("baseInset", () -> baseInset);
-            m.put("startCap", () -> startCap);
-            m.put("endCap", () -> endCap);
-            m.put("join", () -> join);
-            m.put("miterLimit", () -> miterLimit);
-            m.put("widthScale", () -> widthScale);
-            m.put("fillHotSpot", () -> fillHotSpot);
-            m.put("lineHotSpot", () -> lineHotSpot);
-            m.put("fillPath", () -> fillPath);
-            m.put("outlinePath", () -> outlinePath);
-            return Collections.unmodifiableMap(m);
+            return GenericRecordUtil.getGenericProperties(
+                "flags", getBitsAsString(() -> dataFlags, FLAGS_MASKS, FLAGS_NAMES),
+                "baseCap", () -> baseCap,
+                "baseInset", () -> baseInset,
+                "base", super::getGenericProperties,
+                "fillPath", () -> fillPath,
+                "outlinePath", () -> outlinePath
+            );
         }
     }
 
-    public static class EmfPlusAdjustableArrowCap implements EmfPlusCustomLineCap {
+    public static class EmfPlusAdjustableArrowCap extends EmfPlusCustomLineCap {
         private double width;
         private double height;
         private double middleInset;
         private boolean isFilled;
-        private EmfPlusLineCapType startCap;
-        private EmfPlusLineCapType endCap;
-        private EmfPlusLineJoin join;
-        private double miterLimit;
-        private double widthScale;
-        private final Point2D fillHotSpot = new Point2D.Double();
-        private final Point2D lineHotSpot = new Point2D.Double();
 
         @Override
         public long init(LittleEndianInputStream leis) throws IOException {
@@ -719,51 +729,19 @@ public class HemfPlusPen {
             // If the arrow cap is not filled, only the outline is drawn.
             isFilled = (leis.readInt() != 0);
 
-            // A 32-bit unsigned integer that specifies the value in the LineCap enumeration that indicates
-            // the line cap to be used at the start/end of the line to be drawn.
-            startCap = EmfPlusLineCapType.valueOf(leis.readInt());
-            endCap = EmfPlusLineCapType.valueOf(leis.readInt());
-
-            // 32-bit unsigned integer that specifies the value in the LineJoin enumeration that specifies how to
-            // join two lines that are drawn by the same pen and whose ends meet. At the intersection of the two
-            // line ends, a line join makes the connection look more continuous.
-            join = EmfPlusLineJoin.valueOf(leis.readInt());
-
-            // A 32-bit floating-point value that specifies the limit of the thickness of the join on a mitered
-            // corner by setting the maximum allowed ratio of miter length to line width.
-            miterLimit = leis.readFloat();
-
-            // A 32-bit floating-point value that specifies the amount by which to scale an EmfPlusCustomLineCap
-            // object with respect to the width of the graphics pen that is used to draw the lines.
-            widthScale = leis.readFloat();
-
-            int size = 9 * LittleEndianConsts.INT_SIZE;
-
-            // An EmfPlusPointF object that is not currently used. It MUST be set to {0.0, 0.0}.
-            size += readPointF(leis, fillHotSpot);
-
-            // An EmfPlusPointF object that is not currently used. It MUST be set to {0.0, 0.0}.
-            size += readPointF(leis, lineHotSpot);
-
-            return size;
+            return 4*LittleEndianConsts.INT_SIZE + super.init(leis);
         }
 
 
         @Override
         public Map<String, Supplier<?>> getGenericProperties() {
-            final Map<String,Supplier<?>> m = new LinkedHashMap<>();
-            m.put("width", () -> width);
-            m.put("height", () -> height);
-            m.put("middleInset", () -> middleInset);
-            m.put("isFilled", () -> isFilled);
-            m.put("startCap", () -> startCap);
-            m.put("endCap", () -> endCap);
-            m.put("join", () -> join);
-            m.put("miterLimit", () -> miterLimit);
-            m.put("widthScale", () -> widthScale);
-            m.put("fillHotSpot", () -> fillHotSpot);
-            m.put("lineHotSpot", () -> lineHotSpot);
-            return Collections.unmodifiableMap(m);
+            return GenericRecordUtil.getGenericProperties(
+                "width", () -> width,
+                "height", () -> height,
+                "middleInset", () -> middleInset,
+                "isFilled", () -> isFilled,
+                "base", super::getGenericProperties
+            );
         }
     }
 }
index af1cf0935ff59cc27e9b021b2afef7e3279d1c80..3ac27f0dec19560165acd93b099e060da5a0a5d1 100644 (file)
@@ -56,7 +56,7 @@ public interface HemfPlusRecord extends GenericRecord {
     }
 
     @Override
-    default Enum getGenericRecordType() {
+    default HemfPlusRecordType getGenericRecordType() {
         return getEmfPlusRecordType();
     }
 }
index 8862e856b994fbc7638e033e668d206fe757d3a8..9ccfb5ff6a7ce20f3896edd74a3bc46f57167abf 100644 (file)
@@ -108,6 +108,7 @@ public class HemfPlusRegion {
         private final EmfPlusGraphicsVersion graphicsVersion = new EmfPlusGraphicsVersion();
         private EmfPlusRegionNodeData regionNode;
 
+        @SuppressWarnings("unused")
         @Override
         public long init(LittleEndianInputStream leis, long dataSize, EmfPlusObjectType objectType, int flags) throws IOException {
             long size = graphicsVersion.init(leis);
index 9ca1b375eb6b015677d5b231b5c766e167670851..74c8e6c458bdad32fda4abe8659aa6ef92e7ad58 100644 (file)
@@ -30,11 +30,8 @@ import org.apache.poi.util.LittleEndianInputStream;
 @Internal
 public class UnimplementedHemfPlusRecord implements HemfPlusRecord {
 
-    private static final int MAX_RECORD_LENGTH = 1_000_000;
-
     private HemfPlusRecordType recordType;
     private int flags;
-    private byte[] recordBytes;
 
     @Override
     public HemfPlusRecordType getEmfPlusRecordType() {
@@ -50,21 +47,17 @@ public class UnimplementedHemfPlusRecord implements HemfPlusRecord {
     public long init(LittleEndianInputStream leis, long dataSize, long recordId, int flags) throws IOException {
         recordType = HemfPlusRecordType.getById(recordId);
         this.flags = flags;
-        recordBytes = IOUtils.safelyAllocate(dataSize, MAX_RECORD_LENGTH);
-        leis.readFully(recordBytes);
-        return recordBytes.length;
-    }
-
-    public byte[] getRecordBytes() {
-        //should probably defensively return a copy.
-        return recordBytes;
+        long skipped = IOUtils.skipFully(leis, dataSize);
+        if (skipped < dataSize) {
+            throw new IOException("End of stream reached before record read");
+        }
+        return skipped;
     }
 
     @Override
     public Map<String, Supplier<?>> getGenericProperties() {
         return GenericRecordUtil.getGenericProperties(
-            "flags", this::getFlags,
-            "recordBytes", () -> recordBytes
+            "flags", this::getFlags
         );
     }
 }
\ No newline at end of file