You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ZipPackage.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.openxml4j.opc;
  16. import static org.apache.poi.openxml4j.opc.ContentTypes.RELATIONSHIPS_PART;
  17. import static org.apache.poi.openxml4j.opc.internal.ContentTypeManager.CONTENT_TYPES_PART_NAME;
  18. import java.io.File;
  19. import java.io.FileInputStream;
  20. import java.io.FileNotFoundException;
  21. import java.io.IOException;
  22. import java.io.InputStream;
  23. import java.io.OutputStream;
  24. import java.util.Collections;
  25. import java.util.List;
  26. import java.util.stream.Collectors;
  27. import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
  28. import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
  29. import org.apache.commons.compress.archivers.zip.ZipFile;
  30. import org.apache.logging.log4j.LogManager;
  31. import org.apache.logging.log4j.Logger;
  32. import org.apache.logging.log4j.message.SimpleMessage;
  33. import org.apache.poi.UnsupportedFileFormatException;
  34. import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  35. import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
  36. import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException;
  37. import org.apache.poi.openxml4j.exceptions.ODFNotOfficeXmlFileException;
  38. import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
  39. import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException;
  40. import org.apache.poi.openxml4j.opc.internal.*;
  41. import org.apache.poi.openxml4j.opc.internal.marshallers.ZipPartMarshaller;
  42. import org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream;
  43. import org.apache.poi.openxml4j.util.ZipEntrySource;
  44. import org.apache.poi.openxml4j.util.ZipFileZipEntrySource;
  45. import org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource;
  46. import org.apache.poi.util.IOUtils;
  47. import org.apache.poi.util.TempFile;
  48. /**
  49. * Physical zip package.
  50. */
  51. public final class ZipPackage extends OPCPackage {
  52. private static final String MIMETYPE = "mimetype";
  53. private static final String SETTINGS_XML = "settings.xml";
  54. private static boolean useTempFilePackageParts = false;
  55. private static boolean encryptTempFilePackageParts = false;
  56. private static final Logger LOG = LogManager.getLogger(ZipPackage.class);
  57. /**
  58. * Zip archive, as either a file on disk,
  59. * or a stream
  60. */
  61. private final ZipEntrySource zipArchive;
  62. /**
  63. * @param tempFilePackageParts whether to save package part data in temp files to save memory
  64. */
  65. public static void setUseTempFilePackageParts(boolean tempFilePackageParts) {
  66. useTempFilePackageParts = tempFilePackageParts;
  67. }
  68. /**
  69. * @param encryptTempFiles whether to encrypt package part temp files
  70. */
  71. public static void setEncryptTempFilePackageParts(boolean encryptTempFiles) {
  72. encryptTempFilePackageParts = encryptTempFiles;
  73. }
  74. /**
  75. * @return whether package part data is stored in temp files to save memory
  76. */
  77. public static boolean useTempFilePackageParts() {
  78. return useTempFilePackageParts;
  79. }
  80. /**
  81. * @return whether package part temp files are encrypted
  82. */
  83. public static boolean encryptTempFilePackageParts() {
  84. return encryptTempFilePackageParts;
  85. }
  86. /**
  87. * Constructor. Creates a new, empty ZipPackage.
  88. */
  89. public ZipPackage() {
  90. super(defaultPackageAccess);
  91. this.zipArchive = null;
  92. try {
  93. this.contentTypeManager = new ZipContentTypeManager(null, this);
  94. } catch (InvalidFormatException e) {
  95. LOG.atWarn().withThrowable(e).log("Could not parse ZipPackage");
  96. }
  97. }
  98. /**
  99. * Constructor. Opens a Zip based Open XML document from
  100. * an InputStream.
  101. *
  102. * @param in
  103. * Zip input stream to load.
  104. * @param access
  105. * The package access mode.
  106. * @throws IllegalArgumentException
  107. * If the specified input stream is not an instance of
  108. * ZipInputStream.
  109. * @throws IOException
  110. * if input stream cannot be opened, read, or closed
  111. */
  112. ZipPackage(InputStream in, PackageAccess access) throws IOException {
  113. super(access);
  114. ZipArchiveThresholdInputStream zis = ZipHelper.openZipStream(in); // NOSONAR
  115. try {
  116. this.zipArchive = new ZipInputStreamZipEntrySource(zis);
  117. } catch (final IOException e) {
  118. IOUtils.closeQuietly(zis);
  119. throw e;
  120. }
  121. }
  122. /**
  123. * Constructor. Opens a Zip based Open XML document from a file.
  124. *
  125. * @param path
  126. * The path of the file to open or create.
  127. * @param access
  128. * The package access mode.
  129. * @throws InvalidOperationException If the zip file cannot be opened.
  130. */
  131. ZipPackage(String path, PackageAccess access) throws InvalidOperationException {
  132. this(new File(path), access);
  133. }
  134. /**
  135. * Constructor. Opens a Zip based Open XML document from a File.
  136. *
  137. * @param file
  138. * The file to open or create.
  139. * @param access
  140. * The package access mode.
  141. * @throws InvalidOperationException If the zip file cannot be opened.
  142. */
  143. ZipPackage(File file, PackageAccess access) throws InvalidOperationException {
  144. super(access);
  145. ZipEntrySource ze;
  146. try {
  147. final ZipFile zipFile = ZipHelper.openZipFile(file); // NOSONAR
  148. ze = new ZipFileZipEntrySource(zipFile);
  149. } catch (IOException e) {
  150. // probably not happening with write access - not sure how to handle the default read-write access ...
  151. if (access == PackageAccess.WRITE) {
  152. throw new InvalidOperationException("Can't open the specified file: '" + file + "'", e);
  153. }
  154. LOG.atError().log("Error in zip file {} - falling back to stream processing (i.e. ignoring zip central directory)", file);
  155. ze = openZipEntrySourceStream(file);
  156. }
  157. this.zipArchive = ze;
  158. }
  159. private static ZipEntrySource openZipEntrySourceStream(File file) throws InvalidOperationException {
  160. final FileInputStream fis;
  161. // Acquire a resource that is needed to read the next level of openZipEntrySourceStream
  162. try {
  163. // open the file input stream
  164. fis = new FileInputStream(file); // NOSONAR
  165. } catch (final FileNotFoundException e) {
  166. // If the source cannot be acquired, abort (no resources to free at this level)
  167. throw new InvalidOperationException("Can't open the specified file input stream from file: '" + file + "'", e);
  168. }
  169. // If an error occurs while reading the next level of openZipEntrySourceStream, free the acquired resource
  170. try {
  171. // read from the file input stream
  172. return openZipEntrySourceStream(fis);
  173. } catch (final InvalidOperationException|UnsupportedFileFormatException e) {
  174. // abort: close the zip input stream
  175. IOUtils.closeQuietly(fis);
  176. throw e;
  177. } catch (final Exception e) {
  178. // abort: close the file input stream
  179. IOUtils.closeQuietly(fis);
  180. throw new InvalidOperationException("Failed to read the file input stream from file: '" + file + "'", e);
  181. }
  182. }
  183. private static ZipEntrySource openZipEntrySourceStream(FileInputStream fis) throws InvalidOperationException {
  184. final ZipArchiveThresholdInputStream zis;
  185. // Acquire a resource that is needed to read the next level of openZipEntrySourceStream
  186. try {
  187. // open the zip input stream
  188. zis = ZipHelper.openZipStream(fis); // NOSONAR
  189. } catch (final IOException e) {
  190. // If the source cannot be acquired, abort (no resources to free at this level)
  191. throw new InvalidOperationException("Could not open the file input stream", e);
  192. }
  193. // If an error occurs while reading the next level of openZipEntrySourceStream, free the acquired resource
  194. try {
  195. // read from the zip input stream
  196. return openZipEntrySourceStream(zis);
  197. } catch (final InvalidOperationException|UnsupportedFileFormatException e) {
  198. // abort: close the zip input stream
  199. IOUtils.closeQuietly(zis);
  200. throw e;
  201. } catch (final Exception e) {
  202. // abort: close the zip input stream
  203. IOUtils.closeQuietly(zis);
  204. throw new InvalidOperationException("Failed to read the zip entry source stream", e);
  205. }
  206. }
  207. private static ZipEntrySource openZipEntrySourceStream(ZipArchiveThresholdInputStream zis) throws InvalidOperationException {
  208. // Acquire the final level resource. If this is acquired successfully, the zip package was read successfully from the input stream
  209. try {
  210. // open the zip entry source stream
  211. return new ZipInputStreamZipEntrySource(zis);
  212. } catch (IOException e) {
  213. throw new InvalidOperationException("Could not open the specified zip entry source stream", e);
  214. }
  215. }
  216. /**
  217. * Constructor. Opens a Zip based Open XML document from
  218. * a custom ZipEntrySource, typically an open archive
  219. * from another system
  220. *
  221. * @param zipEntry
  222. * Zip data to load.
  223. * @param access
  224. * The package access mode.
  225. */
  226. ZipPackage(ZipEntrySource zipEntry, PackageAccess access) {
  227. super(access);
  228. this.zipArchive = zipEntry;
  229. }
  230. /**
  231. * Retrieves the parts from this package. We assume that the package has not
  232. * been yet inspect to retrieve all the parts, this method will open the
  233. * archive and look for all parts contain inside it.
  234. *
  235. * @return All parts contain in this package.
  236. * @throws InvalidFormatException if the package is not valid.
  237. */
  238. @Override
  239. protected PackagePartCollection getPartsImpl() throws InvalidFormatException {
  240. final PackagePartCollection newPartList = new PackagePartCollection();
  241. if (zipArchive == null) {
  242. return newPartList;
  243. }
  244. // First we need to parse the content type part
  245. final ZipArchiveEntry contentTypeEntry =
  246. zipArchive.getEntry(CONTENT_TYPES_PART_NAME);
  247. if (contentTypeEntry != null) {
  248. if (this.contentTypeManager != null) {
  249. throw new InvalidFormatException("ContentTypeManager can only be created once. This must be a cyclic relation?");
  250. }
  251. try {
  252. this.contentTypeManager = new ZipContentTypeManager(
  253. zipArchive.getInputStream(contentTypeEntry), this);
  254. } catch (IOException e) {
  255. throw new InvalidFormatException(e.getMessage(), e);
  256. }
  257. } else {
  258. // Is it a different Zip-based format?
  259. final boolean hasMimetype = zipArchive.getEntry(MIMETYPE) != null;
  260. final boolean hasSettingsXML = zipArchive.getEntry(SETTINGS_XML) != null;
  261. if (hasMimetype && hasSettingsXML) {
  262. throw new ODFNotOfficeXmlFileException(
  263. "The supplied data appears to be in ODF (Open Document) Format. " +
  264. "Formats like these (eg ODS, ODP) are not supported, try Apache ODFToolkit");
  265. }
  266. if (!zipArchive.getEntries().hasMoreElements()) {
  267. throw new NotOfficeXmlFileException(
  268. "No valid entries or contents found, this is not a valid OOXML " +
  269. "(Office Open XML) file");
  270. }
  271. // Fallback exception
  272. throw new InvalidFormatException(
  273. "Package should contain a content type part [M1.13]");
  274. }
  275. // Now create all the relationships
  276. // (Need to create relationships before other
  277. // parts, otherwise we might create a part before
  278. // its relationship exists, and then it won't tie up)
  279. final List<EntryTriple> entries =
  280. Collections.list(zipArchive.getEntries()).stream()
  281. .map(zae -> new EntryTriple(zae, contentTypeManager))
  282. .filter(mm -> mm.partName != null)
  283. .sorted()
  284. .collect(Collectors.toList());
  285. for (final EntryTriple et : entries) {
  286. et.register(newPartList);
  287. }
  288. return newPartList;
  289. }
  290. private class EntryTriple implements Comparable<EntryTriple> {
  291. final ZipArchiveEntry zipArchiveEntry;
  292. final PackagePartName partName;
  293. final String contentType;
  294. EntryTriple(final ZipArchiveEntry zipArchiveEntry, final ContentTypeManager contentTypeManager) {
  295. this.zipArchiveEntry = zipArchiveEntry;
  296. final String entryName = zipArchiveEntry.getName();
  297. PackagePartName ppn = null;
  298. // ignore trash parts
  299. if (!entryName.startsWith("[trash]")) {
  300. try {
  301. // We get an error when we parse [Content_Types].xml
  302. // because it's not a valid URI.
  303. ppn = (CONTENT_TYPES_PART_NAME.equalsIgnoreCase(entryName)) ? null
  304. : PackagingURIHelper.createPartName(ZipHelper.getOPCNameFromZipItemName(entryName));
  305. } catch (Exception e) {
  306. // We assume we can continue, even in degraded mode ...
  307. LOG.atWarn().withThrowable(e).log("Entry {} is not valid, so this part won't be added to the package.", entryName);
  308. }
  309. }
  310. this.partName = ppn;
  311. this.contentType = (ppn == null) ? null : contentTypeManager.getContentType(partName);
  312. }
  313. void register(final PackagePartCollection partList) throws InvalidFormatException {
  314. if (contentType == null) {
  315. throw new InvalidFormatException("The part " + partName.getURI().getPath() + " does not have any " +
  316. "content type ! Rule: Package require content types when retrieving a part from a package. [M.1.14]");
  317. }
  318. if (partList.containsKey(partName)) {
  319. throw new InvalidFormatException(
  320. "A part with the name '"+partName+"' already exists : Packages shall not contain equivalent part names " +
  321. "and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
  322. }
  323. try {
  324. partList.put(partName, new ZipPackagePart(ZipPackage.this, zipArchiveEntry, partName, contentType, false));
  325. } catch (InvalidOperationException e) {
  326. throw new InvalidFormatException(e.getMessage(), e);
  327. }
  328. }
  329. @Override
  330. public int compareTo(EntryTriple o) {
  331. final int contentTypeOrder1 = RELATIONSHIPS_PART.equals(contentType) ? -1 : 1;
  332. final int contentTypeOrder2 = RELATIONSHIPS_PART.equals(o.contentType) ? -1 : 1;
  333. final int cmpCT = Integer.compare(contentTypeOrder1, contentTypeOrder2);
  334. return cmpCT != 0 ? cmpCT : partName.compareTo(o.partName);
  335. }
  336. }
  337. /**
  338. * Create a new MemoryPackagePart from the specified URI and content type
  339. *
  340. * @param partName
  341. * The part name.
  342. * @param contentType
  343. * The part content type.
  344. * @param loadRelationships
  345. * whether to load relationships.
  346. * @return The newly created zip package part, else <b>null</b>.
  347. * @throws IllegalArgumentException if partName or contentType is null
  348. */
  349. @Override
  350. protected PackagePart createPartImpl(PackagePartName partName,
  351. String contentType, boolean loadRelationships) {
  352. if (contentType == null) {
  353. throw new IllegalArgumentException("contentType");
  354. }
  355. if (partName == null) {
  356. throw new IllegalArgumentException("partName");
  357. }
  358. try {
  359. if (useTempFilePackageParts) {
  360. if (encryptTempFilePackageParts) {
  361. return new EncryptedTempFilePackagePart(this, partName, contentType, loadRelationships);
  362. } else {
  363. return new TempFilePackagePart(this, partName, contentType, loadRelationships);
  364. }
  365. } else {
  366. return new MemoryPackagePart(this, partName, contentType, loadRelationships);
  367. }
  368. } catch (Exception e) {
  369. LOG.atWarn().withThrowable(e).log("Failed to create part {}", partName);
  370. return null;
  371. }
  372. }
  373. /**
  374. * Delete a part from the package
  375. *
  376. * @throws IllegalArgumentException
  377. * Throws if the part URI is null or invalid.
  378. */
  379. @Override
  380. protected void removePartImpl(PackagePartName partName) {
  381. if (partName == null) {
  382. throw new IllegalArgumentException("partUri");
  383. }
  384. }
  385. /**
  386. * Flush the package. Do nothing.
  387. */
  388. @Override
  389. protected void flushImpl() {
  390. // Do nothing
  391. }
  392. /**
  393. * Close and save the package.
  394. *
  395. * @see #close()
  396. */
  397. @Override
  398. protected void closeImpl() throws IOException {
  399. // Flush the package
  400. flush();
  401. if (this.originalPackagePath == null || this.originalPackagePath.isEmpty()) {
  402. return;
  403. }
  404. // Save the content
  405. File targetFile = new File(this.originalPackagePath);
  406. if (!targetFile.exists()) {
  407. throw new InvalidOperationException(
  408. "Can't close a package not previously open with the open() method !");
  409. }
  410. // Case of a package previously open
  411. String tempFileName = generateTempFileName(FileHelper.getDirectory(targetFile));
  412. File tempFile = TempFile.createTempFile(tempFileName, ".tmp");
  413. // Save the final package to a temporary file
  414. boolean success = false;
  415. try {
  416. save(tempFile);
  417. success = true;
  418. } finally {
  419. // Close the current zip file, so we can overwrite it on all platforms
  420. IOUtils.closeQuietly(this.zipArchive);
  421. try {
  422. // Copy the new file over the old one if save() succeed
  423. if(success) {
  424. FileHelper.copyFile(tempFile, targetFile);
  425. }
  426. } finally {
  427. // Either the save operation succeed or not, we delete the temporary file
  428. if (!tempFile.delete()) {
  429. LOG.atWarn().log("The temporary file: '{}' cannot be deleted ! Make sure that no other application use it.", targetFile.getAbsolutePath());
  430. }
  431. }
  432. }
  433. }
  434. /**
  435. * Create a unique identifier to be use as a temp file name.
  436. *
  437. * @return A unique identifier use to be use as a temp file name.
  438. */
  439. private synchronized String generateTempFileName(File directory) {
  440. File tmpFilename;
  441. do {
  442. tmpFilename = new File(directory.getAbsoluteFile() + File.separator
  443. + "OpenXML4J" + System.nanoTime());
  444. } while (tmpFilename.exists());
  445. return FileHelper.getFilename(tmpFilename.getAbsoluteFile());
  446. }
  447. /**
  448. * Close the package without saving the document. Discard all the changes
  449. * made to this package.
  450. */
  451. @Override
  452. protected void revertImpl() {
  453. try {
  454. if (this.zipArchive != null) {
  455. this.zipArchive.close();
  456. }
  457. } catch (IOException e) {
  458. // Do nothing, user dont have to know
  459. }
  460. }
  461. /**
  462. * Save this package into the specified stream
  463. *
  464. *
  465. * @param outputStream
  466. * The stream use to save this package.
  467. *
  468. * @see #save(OutputStream)
  469. */
  470. @Override
  471. public void saveImpl(OutputStream outputStream) {
  472. // Check that the document was open in write mode
  473. throwExceptionIfReadOnly();
  474. final ZipArchiveOutputStream zos = (outputStream instanceof ZipArchiveOutputStream)
  475. ? (ZipArchiveOutputStream) outputStream : new ZipArchiveOutputStream(outputStream);
  476. try {
  477. // If the core properties part does not exist in the part list,
  478. // we save it as well
  479. if (this.getPartsByRelationshipType(PackageRelationshipTypes.CORE_PROPERTIES).size() == 0 &&
  480. this.getPartsByRelationshipType(PackageRelationshipTypes.CORE_PROPERTIES_ECMA376).size() == 0 ) {
  481. LOG.atDebug().log("Save core properties part");
  482. // Ensure that core properties are added if missing
  483. getPackageProperties();
  484. // Add core properties to part list ...
  485. addPackagePart(this.packageProperties);
  486. // ... and to add its relationship ...
  487. this.relationships.addRelationship(this.packageProperties
  488. .getPartName().getURI(), TargetMode.INTERNAL,
  489. PackageRelationshipTypes.CORE_PROPERTIES, null);
  490. // ... and the content if it has not been added yet.
  491. if (!this.contentTypeManager
  492. .isContentTypeRegister(ContentTypes.CORE_PROPERTIES_PART)) {
  493. this.contentTypeManager.addContentType(
  494. this.packageProperties.getPartName(),
  495. ContentTypes.CORE_PROPERTIES_PART);
  496. }
  497. }
  498. // Save content type part.
  499. LOG.atDebug().log("Save content types part");
  500. this.contentTypeManager.save(zos);
  501. // Save package relationships part.
  502. LOG.atDebug().log("Save package relationships");
  503. ZipPartMarshaller.marshallRelationshipPart(this.getRelationships(),
  504. PackagingURIHelper.PACKAGE_RELATIONSHIPS_ROOT_PART_NAME,
  505. zos);
  506. // Save parts.
  507. for (PackagePart part : getParts()) {
  508. // If the part is a relationship part, we don't save it, it's
  509. // the source part that will do the job.
  510. if (part.isRelationshipPart()) {
  511. continue;
  512. }
  513. final PackagePartName ppn = part.getPartName();
  514. LOG.atDebug().log(() -> new SimpleMessage("Save part '" + ZipHelper.getZipItemNameFromOPCName(ppn.getName()) + "'"));
  515. final PartMarshaller marshaller = partMarshallers.get(part._contentType);
  516. final PartMarshaller pm = (marshaller != null) ? marshaller : defaultPartMarshaller;
  517. if (!pm.marshall(part, zos)) {
  518. String errMsg = "The part " + ppn.getURI() + " failed to be saved in the stream with marshaller " + pm +
  519. ". Enable logging via Log4j 2 for more details.";
  520. throw new OpenXML4JException(errMsg);
  521. }
  522. }
  523. zos.finish();
  524. } catch (OpenXML4JRuntimeException e) {
  525. // no need to wrap this type of Exception
  526. throw e;
  527. } catch (Exception e) {
  528. throw new OpenXML4JRuntimeException(
  529. "Fail to save: an error occurs while saving the package : "
  530. + e.getMessage(), e);
  531. }
  532. }
  533. /**
  534. * Get the zip archive
  535. *
  536. * @return The zip archive.
  537. */
  538. public ZipEntrySource getZipArchive() {
  539. return zipArchive;
  540. }
  541. @Override
  542. public boolean isClosed() {
  543. // if zipArchive == null, it might be created on the fly
  544. // so only return true, if a zip archive was initialized before
  545. return zipArchive != null && zipArchive.isClosed();
  546. }
  547. }