Author: fanningpj
Date: Sat Aug  5 22:20:38 2023
New Revision: 1911470

URL: http://svn.apache.org/viewvc?rev=1911470&view=rev
Log:
avoid creating enumeration twice

Modified:
    
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java
    
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java

Modified: 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java?rev=1911470&r1=1911469&r2=1911470&view=diff
==============================================================================
--- 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java 
(original)
+++ 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java 
Sat Aug  5 22:20:38 2023
@@ -27,6 +27,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Collections;
+import java.util.Enumeration;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -271,6 +272,7 @@ public final class ZipPackage extends OP
         // First we need to parse the content type part
         final ZipArchiveEntry contentTypeEntry =
                 zipArchive.getEntry(CONTENT_TYPES_PART_NAME);
+        final Enumeration<? extends ZipArchiveEntry> zipEntries;
         if (contentTypeEntry != null) {
             if (this.contentTypeManager != null) {
                 throw new InvalidFormatException("ContentTypeManager can only 
be created once. This must be a cyclic relation?");
@@ -281,6 +283,7 @@ public final class ZipPackage extends OP
             } catch (IOException e) {
                 throw new InvalidFormatException(e.getMessage(), e);
             }
+            zipEntries = zipArchive.getEntries();
         } else {
             // Is it a different Zip-based format?
             final boolean hasMimetype = zipArchive.getEntry(MIMETYPE) != null;
@@ -290,7 +293,8 @@ public final class ZipPackage extends OP
                         "The supplied data appears to be in ODF (Open 
Document) Format. " +
                                 "Formats like these (eg ODS, ODP) are not 
supported, try Apache ODFToolkit");
             }
-            if (!zipArchive.getEntries().hasMoreElements()) {
+            zipEntries = zipArchive.getEntries();
+            if (!zipEntries.hasMoreElements()) {
                 throw new NotOfficeXmlFileException(
                         "No valid entries or contents found, this is not a 
valid OOXML " +
                                 "(Office Open XML) file");
@@ -305,7 +309,7 @@ public final class ZipPackage extends OP
         //  parts, otherwise we might create a part before
         //  its relationship exists, and then it won't tie up)
         final List<EntryTriple> entries =
-                Collections.list(zipArchive.getEntries()).stream()
+                Collections.list(zipEntries).stream()
                         .filter(zipArchiveEntry -> 
!ignoreEntry(zipArchiveEntry))
                         .map(zae -> new EntryTriple(zae, contentTypeManager))
                         .filter(mm -> mm.partName != null)

Modified: 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java?rev=1911470&r1=1911469&r2=1911470&view=diff
==============================================================================
--- 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
 (original)
+++ 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
 Sat Aug  5 22:20:38 2023
@@ -55,7 +55,7 @@ public class ZipInputStreamZipEntrySourc
     }
 
     /**
-     * Get the threshold at which it a zip entry is regarded as too large for 
holding in memory
+     * Get the threshold at which a zip entry is regarded as too large for 
holding in memory
      * and the data is put in a temp file instead (defaults to -1 meaning temp 
files are not used)
      * @return threshold in bytes
      * @since POI 5.1.0



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to