You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2019/09/14 10:11:41 UTC

svn commit: r1866935 - /poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java

Author: fanningpj
Date: Sat Sep 14 10:11:41 2019
New Revision: 1866935

URL: http://svn.apache.org/viewvc?rev=1866935&view=rev
Log:
try to avoid casting to int

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java?rev=1866935&r1=1866934&r2=1866935&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java Sat Sep 14 10:11:41 2019
@@ -104,7 +104,7 @@ public class HemfComment {
         @Override
         public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
             int startIdx = leis.getReadIndex();
-            data = new EmfCommentDataIterator(leis, (int)recordSize, true).next();
+            data = new EmfCommentDataIterator(leis, Math.toIntExact(recordSize), true).next();
             return leis.getReadIndex()-startIdx;
         }
 
@@ -198,9 +198,9 @@ public class HemfComment {
                 // Valid comment identifier values are listed in the following table.
                 //
                 // If this field contains any other value, the comment record MUST be an EMR_COMMENT record
-                final int commentIdentifier = (int)leis.readUInt();
+                final int commentIdentifier = Math.toIntExact(leis.readUInt());
                 // A 32-bit unsigned integer that identifies the type of public comment record.
-                final int publicCommentIdentifier = (int)leis.readUInt();
+                final int publicCommentIdentifier = Math.toIntExact(leis.readUInt());
 
                 final boolean isEmfPublic = (commentIdentifier == HemfCommentRecordType.emfPublic.id);
                 leis.reset();
@@ -211,7 +211,7 @@ public class HemfComment {
                 final EmfCommentData record = commentType.constructor.get();
 
                 long readBytes = record.init(leis, dataSize);
-                final int skipBytes = (int)(recordSize-4-readBytes);
+                final int skipBytes = Math.toIntExact(recordSize-4-readBytes);
                 assert (skipBytes >= 0);
                 leis.skipFully(skipBytes);
 
@@ -286,7 +286,7 @@ public class HemfComment {
             long startIdx = leis.getReadIndex();
             int commentIdentifier = leis.readInt();
             assert (commentIdentifier == HemfCommentRecordType.emfPlus.id);
-            new HemfPlusRecordIterator(leis, (int)dataSize-LittleEndianConsts.INT_SIZE).forEachRemaining(records::add);
+            new HemfPlusRecordIterator(leis, Math.toIntExact(dataSize-LittleEndianConsts.INT_SIZE)).forEachRemaining(records::add);
             return leis.getReadIndex()-startIdx;
         }
 
@@ -322,14 +322,14 @@ 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();
+            final int commentIdentifier = Math.toIntExact(leis.readUInt());
             assert(commentIdentifier == HemfCommentRecordType.emfPublic.id);
-            final int publicCommentIdentifier = (int)leis.readUInt();
+            final int publicCommentIdentifier = Math.toIntExact(leis.readUInt());
             assert(publicCommentIdentifier == HemfCommentRecordType.emfBeginGroup.id);
             HemfDraw.readRectL(leis, bounds);
 
             // The number of Unicode characters in the optional description string that follows.
-            int nDescription = (int)leis.readUInt();
+            int nDescription = Math.toIntExact(leis.readUInt());
 
             byte[] buf = IOUtils.safelyAllocate(nDescription * 2L, MAX_RECORD_LENGTH);
             leis.readFully(buf);
@@ -365,9 +365,9 @@ 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();
+            final int commentIdentifier = Math.toIntExact(leis.readUInt());
             assert(commentIdentifier == HemfCommentRecordType.emfPublic.id);
-            final int publicCommentIdentifier = (int)leis.readUInt();
+            final int publicCommentIdentifier = Math.toIntExact(leis.readUInt());
             assert(publicCommentIdentifier == HemfCommentRecordType.emfEndGroup.id);
             return leis.getReadIndex()-startIdx;
         }
@@ -391,14 +391,14 @@ 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();
+            final int commentIdentifier = Math.toIntExact(leis.readUInt());
             assert(commentIdentifier == HemfCommentRecordType.emfPublic.id);
-            final int publicCommentIdentifier = (int)leis.readUInt();
+            final int publicCommentIdentifier = Math.toIntExact(leis.readUInt());
             assert(publicCommentIdentifier == HemfCommentRecordType.emfMultiFormats.id);
             HemfDraw.readRectL(leis, bounds);
 
             // A 32-bit unsigned integer that specifies the number of graphics formats contained in this record.
-            int countFormats = (int)leis.readUInt();
+            int countFormats = Math.toIntExact(leis.readUInt());
             for (int i=0; i<countFormats; i++) {
                 EmfCommentDataFormat fmt = new EmfCommentDataFormat();
                 long readBytes = fmt.init(leis, dataSize, startIdx);
@@ -533,9 +533,9 @@ public class HemfComment {
         @Override
         public long init(final LittleEndianInputStream leis, final long dataSize) throws IOException {
             final int startIdx = leis.getReadIndex();
-            final int commentIdentifier = (int)leis.readUInt();
+            final int commentIdentifier = Math.toIntExact(leis.readUInt());
             assert(commentIdentifier == HemfCommentRecordType.emfPublic.id);
-            final int publicCommentIdentifier = (int)leis.readUInt();
+            final int publicCommentIdentifier = Math.toIntExact(leis.readUInt());
             assert(publicCommentIdentifier == HemfCommentRecordType.emfWMF.id);
 
             // A 16-bit unsigned integer that specifies the WMF metafile version in terms
@@ -553,7 +553,7 @@ public class HemfComment {
 
             // A 32-bit unsigned integer that specifies the size, in bytes, of the
             // WMF metafile in the WinMetafile field.
-            int winMetafileSize = (int)leis.readUInt();
+            int winMetafileSize = Math.toIntExact(leis.readUInt());
 
             wmfData = IOUtils.safelyAllocate(winMetafileSize, MAX_RECORD_LENGTH);
             // some emf comments are truncated, so we don't use readFully here
@@ -586,8 +586,7 @@ 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 {
             throw new RecordFormatException("UNICODE_STRING/UNICODE_END values are reserved in CommentPublic records");
         }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org