aboutsummaryrefslogtreecommitdiffstats
path: root/poi-ooxml
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2023-08-05 22:20:38 +0000
committerPJ Fanning <fanningpj@apache.org>2023-08-05 22:20:38 +0000
commit91c4ec6a458378eec0120073e4a8df3e5d03b1ac (patch)
tree7d67a1e7dda43bef5379463e496c15cd99d64d36 /poi-ooxml
parentddef604f46125cf8ce8084f298d22498d31b1bc1 (diff)
downloadpoi-91c4ec6a458378eec0120073e4a8df3e5d03b1ac.tar.gz
poi-91c4ec6a458378eec0120073e4a8df3e5d03b1ac.zip
avoid creating enumeration twice
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1911470 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml')
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java8
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java2
2 files changed, 7 insertions, 3 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java
index dc176b441b..5c7d798196 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java
@@ -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 OPCPackage {
// 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 OPCPackage {
} 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 OPCPackage {
"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 OPCPackage {
// 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)
diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
index f47418e721..5f9a057d4f 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
@@ -55,7 +55,7 @@ public class ZipInputStreamZipEntrySource implements ZipEntrySource {
}
/**
- * 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