summaryrefslogtreecommitdiff
path: root/java/util/zip/ZipFile.java
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-03-16 14:30:11 +0000
committerRoman Kennke <roman@kennke.org>2006-03-16 14:30:11 +0000
commit818ff0cd1b22e886cd20d404017aabaf8d5f0250 (patch)
tree6304ff3c0716a4aa3292a9dd6da3fc8d891a9f6d /java/util/zip/ZipFile.java
parent9945b1c8fc323b57b526272f564c52017610c5e2 (diff)
downloadclasspath-818ff0cd1b22e886cd20d404017aabaf8d5f0250.tar.gz
2006-03-16 Roman Kennke <kennke@aicas.com>
* java/util/zip/ZipFile.java (openFile): New helper method. (ZipFile): Use new openFile method to ensure the proper exception is thrown. This applies for all overloaded constructors.
Diffstat (limited to 'java/util/zip/ZipFile.java')
-rw-r--r--java/util/zip/ZipFile.java38
1 files changed, 35 insertions, 3 deletions
diff --git a/java/util/zip/ZipFile.java b/java/util/zip/ZipFile.java
index fbfdf7d1a..5c0fe17d6 100644
--- a/java/util/zip/ZipFile.java
+++ b/java/util/zip/ZipFile.java
@@ -43,6 +43,7 @@ import gnu.java.util.EmptyEnumeration;
import java.io.EOFException;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
@@ -91,6 +92,37 @@ public class ZipFile implements ZipConstants
private boolean closed = false;
+
+ /**
+ * Helper function to open RandomAccessFile and throw the proper
+ * ZipException in case opening the file fails.
+ *
+ * @param name the file name, or null if file is provided
+ *
+ * @param file the file, or null if name is provided
+ *
+ * @return the newly open RandomAccessFile, never null
+ */
+ private RandomAccessFile openFile(String name,
+ File file)
+ throws ZipException, IOException
+ {
+ try
+ {
+ return
+ (name != null)
+ ? new RandomAccessFile(name, "r")
+ : new RandomAccessFile(file, "r");
+ }
+ catch (FileNotFoundException f)
+ {
+ ZipException ze = new ZipException(f.getMessage());
+ ze.initCause(f);
+ throw ze;
+ }
+ }
+
+
/**
* Opens a Zip file with the given name for reading.
* @exception IOException if a i/o error occured.
@@ -99,7 +131,7 @@ public class ZipFile implements ZipConstants
*/
public ZipFile(String name) throws ZipException, IOException
{
- this.raf = new RandomAccessFile(name, "r");
+ this.raf = openFile(name,null);
this.name = name;
checkZipFile();
}
@@ -112,7 +144,7 @@ public class ZipFile implements ZipConstants
*/
public ZipFile(File file) throws ZipException, IOException
{
- this.raf = new RandomAccessFile(file, "r");
+ this.raf = openFile(null,file);
this.name = file.getPath();
checkZipFile();
}
@@ -139,7 +171,7 @@ public class ZipFile implements ZipConstants
throw new IllegalArgumentException("invalid mode");
if ((mode & OPEN_DELETE) != 0)
file.deleteOnExit();
- this.raf = new RandomAccessFile(file, "r");
+ this.raf = openFile(null,file);
this.name = file.getPath();
checkZipFile();
}