diff options
author | Mark Wielaard <mark@klomp.org> | 2000-08-27 22:26:27 +0000 |
---|---|---|
committer | Mark Wielaard <mark@gcc.gnu.org> | 2000-08-27 22:26:27 +0000 |
commit | 9ac96ca1f475583f602530b1746add88f0130552 (patch) | |
tree | a46a5682294e3e06ba5793c02331a7c8ab8e3167 /libjava | |
parent | 6f09c307172fb7beb8202da1ca8cb44346f4874c (diff) | |
download | gcc-9ac96ca1f475583f602530b1746add88f0130552.zip gcc-9ac96ca1f475583f602530b1746add88f0130552.tar.gz gcc-9ac96ca1f475583f602530b1746add88f0130552.tar.bz2 |
ZipFile.java: Implement OPEN_DELETE mode...
* java/util/zip/ZipFile.java: Implement OPEN_DELETE mode, new constructor,
close can delete the file, finalize calls close.
* java/util/jar/JarFile.java: Constructor that takes mode now calls super.
From-SVN: r36007
Diffstat (limited to 'libjava')
-rw-r--r-- | libjava/ChangeLog | 6 | ||||
-rw-r--r-- | libjava/java/util/jar/JarFile.java | 22 | ||||
-rw-r--r-- | libjava/java/util/zip/ZipFile.java | 35 |
3 files changed, 49 insertions, 14 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 222bb3c..e3a76e7 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,9 @@ +2000-08-27 Mark Wielaard <mark@klomp.org> + + * java/util/zip/ZipFile.java: Implement OPEN_DELETE mode, new constructor, + close can delete the file, finalize calls close. + * java/util/jar/JarFile.java: Constructor that takes mode now calls super. + 2000-08-27 Anthony Green <green@redhat.com> * java/util/ArrayList.java, java/util/Timer.java, diff --git a/libjava/java/util/jar/JarFile.java b/libjava/java/util/jar/JarFile.java index a266f30..5e0f73b 100644 --- a/libjava/java/util/jar/JarFile.java +++ b/libjava/java/util/jar/JarFile.java @@ -129,15 +129,17 @@ public class JarFile extends ZipFile { } /** - * XXX - not yet implemented in java.util.zip.ZipFile + * Creates a new JarFile with the indicated mode, tries to read the + * manifest and if the manifest exists and verify is true verfies it. * * @param file the file to open to open as a jar file * @param verify checks manifest and entries when true and a manifest * exists, when false no checks are made - * @param mode XXX - see ZipFile - * @exception FileNotFoundException XXX - * @exception IOException XXX - * @exception IllegalArgumentException XXX + * @param mode either ZipFile.OPEN_READ or + * (ZipFile.OPEN_READ | ZipFile.OPEN_DELETE) + * @exception FileNotFoundException if the file does not exist + * @exception IOException if another IO exception occurs while reading + * @exception IllegalArgumentException when given an illegal mode * * @since 1.3 */ @@ -145,12 +147,10 @@ public class JarFile extends ZipFile { FileNotFoundException, IOException, IllegalArgumentException { - // XXX - For now don't use super(file, mode) - this(file, verify); - /* super(file, mode); - manifest = readManifest(); - if (verify) - verify(); */ + super(file, mode); + manifest = readManifest(); + if (verify) + verify(); } // Methods diff --git a/libjava/java/util/zip/ZipFile.java b/libjava/java/util/zip/ZipFile.java index 43d7226..bb6eab4 100644 --- a/libjava/java/util/zip/ZipFile.java +++ b/libjava/java/util/zip/ZipFile.java @@ -18,15 +18,35 @@ import java.io.*; public class ZipFile implements ZipConstants { + public static final int OPEN_READ = 1; + public static final int OPEN_DELETE = 4; + public ZipFile (String fname) throws IOException { - file = new RandomAccessFile(fname, "r"); - name = fname; - readDirectory (); + this(new File(fname)); } public ZipFile (File f) throws IOException { + this(f, OPEN_READ); + } + + public ZipFile (File f, int mode) throws IOException + { + if (mode != OPEN_READ && mode != (OPEN_READ | OPEN_DELETE)) + throw new IllegalArgumentException + ("mode can only be OPEN_READ or OPEN_READ | OPEN_DELETE"); + + if ((mode & OPEN_DELETE) != 0) + { + delete_on_close = f; + // f.deleteOnExit(); XXX - Not yet implemented in libgcj + } + else + { + delete_on_close = null; + } + file = new RandomAccessFile(f, "r"); name = f.getName(); readDirectory (); @@ -107,6 +127,8 @@ public class ZipFile implements ZipConstants file.close(); entries = null; numEntries = 0; + if (delete_on_close != null) + delete_on_close.delete(); } public ZipEntry getEntry(String name) @@ -148,6 +170,10 @@ public class ZipFile implements ZipConstants return numEntries; } + protected void finalize () throws IOException { + close(); + } + private int readu2 () throws IOException { int byte0 = file.read(); @@ -173,6 +199,9 @@ public class ZipFile implements ZipConstants int numEntries; RandomAccessFile file; String name; + /** File to delete on close or null. */ + File delete_on_close; + } final class ZipEnumeration implements java.util.Enumeration |