From 9fb8683aa383e26a741b19213699452a3dcecc17 Mon Sep 17 00:00:00 2001 From: Maxim Valyanskiy Date: Tue, 20 Mar 2012 11:21:23 +0000 Subject: [PATCH] OPC: add original IOException to chain on open file errors git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1302840 13f79535-47bb-0310-9956-ffa450edef68 --- .../exceptions/InvalidOperationException.java | 4 ++++ .../org/apache/poi/openxml4j/opc/ZipPackage.java | 13 +++++++++---- .../poi/openxml4j/opc/internal/ZipHelper.java | 12 +++++------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/openxml4j/exceptions/InvalidOperationException.java b/src/ooxml/java/org/apache/poi/openxml4j/exceptions/InvalidOperationException.java index a2538a6d19..7a8338ed81 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/exceptions/InvalidOperationException.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/exceptions/InvalidOperationException.java @@ -25,4 +25,8 @@ public class InvalidOperationException extends OpenXML4JRuntimeException{ public InvalidOperationException(String message){ super(message); } + + public InvalidOperationException(String message, Throwable reason){ + super(message, reason); + } } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java index bc65412bc7..5ac16d3a0b 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java @@ -98,10 +98,15 @@ public final class ZipPackage extends Package { ZipPackage(String path, PackageAccess access) { super(access); - ZipFile zipFile = ZipHelper.openZipFile(path); - if (zipFile == null) - throw new InvalidOperationException( - "Can't open the specified file: '" + path + "'"); + ZipFile zipFile = null; + + try { + zipFile = ZipHelper.openZipFile(path); + } catch (IOException e) { + throw new InvalidOperationException( + "Can't open the specified file: '" + path + "'", e); + } + this.zipArchive = new ZipFileZipEntrySource(zipFile); } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java index cbfd5a7ee5..e808dc61e9 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java @@ -148,15 +148,13 @@ public final class ZipHelper { * The file path. * @return The zip archive freshly open. */ - public static ZipFile openZipFile(String path) { + public static ZipFile openZipFile(String path) throws IOException { File f = new File(path); - try { - if (!f.exists()) { - return null; - } - return new ZipFile(f); - } catch (IOException ioe) { + + if (!f.exists()) { return null; } + + return new ZipFile(f); } } -- 2.39.5