* Physical zip package.
*/
public final class ZipPackage extends OPCPackage {
+ private static final String MIMETYPE = "mimetype";
+ private static final String SETTINGS_XML = "settings.xml";
+
private static POILogger logger = POILogFactory.getLogger(ZipPackage.class);
/**
} catch (final IOException e2) {
throw new InvalidOperationException("Failed to read the zip entry source stream and could not close the zip input stream", e2);
}
- throw new InvalidOperationException("Failed to read the zip entry source stream");
+ throw new InvalidOperationException("Failed to read the zip entry source stream", e);
}
}
this.contentTypeManager = new ZipContentTypeManager(
getZipArchive().getInputStream(entry), this);
} catch (IOException e) {
- throw new InvalidFormatException(e.getMessage());
+ throw new InvalidFormatException(e.getMessage(), e);
}
break;
}
while (entries.hasMoreElements()) {
final ZipEntry entry = entries.nextElement();
final String name = entry.getName();
- if ("mimetype".equals(name)) {
+ if (MIMETYPE.equals(name)) {
hasMimetype = true;
}
- if ("settings.xml".equals(name)) {
+ if (SETTINGS_XML.equals(name)) {
hasSettingsXML = true;
}
numEntries++;
String contentType = contentTypeManager.getContentType(partName);
if (contentType != null && contentType.equals(ContentTypes.RELATIONSHIPS_PART)) {
try {
- partList.put(partName, new ZipPackagePart(this, entry,
- partName, contentType));
+ PackagePart part = new ZipPackagePart(this, entry, partName, contentType);
+ partList.put(partName, part);
} catch (InvalidOperationException e) {
- throw new InvalidFormatException(e.getMessage());
+ throw new InvalidFormatException(e.getMessage(), e);
}
}
}
PackagePartName partName = buildPartName(entry);
if(partName == null) continue;
- String contentType = contentTypeManager
- .getContentType(partName);
+ String contentType = contentTypeManager.getContentType(partName);
if (contentType != null && contentType.equals(ContentTypes.RELATIONSHIPS_PART)) {
// Already handled
}
else if (contentType != null) {
try {
- partList.put(partName, new ZipPackagePart(this, entry,
- partName, contentType));
+ PackagePart part = new ZipPackagePart(this, entry, partName, contentType);
+ partList.put(partName, part);
} catch (InvalidOperationException e) {
- throw new InvalidFormatException(e.getMessage());
+ throw new InvalidFormatException(e.getMessage(), e);
}
} else {
throw new InvalidFormatException(
// Save the final package to a temporary file
try {
save(tempFile);
-
- // Close the current zip file, so we can
- // overwrite it on all platforms
- this.zipArchive.close();
- // Copy the new file over the old one
- FileHelper.copyFile(tempFile, targetFile);
} finally {
- // Either the save operation succeed or not, we delete the
- // temporary file
- if (!tempFile.delete()) {
- logger
- .log(POILogger.WARN,"The temporary file: '"
- + targetFile.getAbsolutePath()
- + "' cannot be deleted ! Make sure that no other application use it.");
+ try {
+ // Close the current zip file, so we can
+ // overwrite it on all platforms
+ this.zipArchive.close();
+ // Copy the new file over the old one
+ FileHelper.copyFile(tempFile, targetFile);
+ } finally {
+ // Either the save operation succeed or not, we delete the
+ // temporary file
+ if (!tempFile.delete()) {
+ logger
+ .log(POILogger.WARN,"The temporary file: '"
+ + targetFile.getAbsolutePath()
+ + "' cannot be deleted ! Make sure that no other application use it.");
+ }
}
}
} else {