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
This commit is contained in:
Maxim Valyanskiy 2012-03-20 11:21:23 +00:00
parent c03bcf23d4
commit c0571bdce3
3 changed files with 18 additions and 11 deletions

View File

@ -25,4 +25,8 @@ public class InvalidOperationException extends OpenXML4JRuntimeException{
public InvalidOperationException(String message){
super(message);
}
public InvalidOperationException(String message, Throwable reason){
super(message, reason);
}
}

View File

@ -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);
}

View File

@ -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);
}
}