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 25KB

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