Commit 9ac96ca1 by Mark Wielaard Committed by Mark Wielaard

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
parent 6f09c307
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> 2000-08-27 Anthony Green <green@redhat.com>
* java/util/ArrayList.java, java/util/Timer.java, * java/util/ArrayList.java, java/util/Timer.java,
......
...@@ -129,15 +129,17 @@ public class JarFile extends ZipFile { ...@@ -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 file the file to open to open as a jar file
* @param verify checks manifest and entries when true and a manifest * @param verify checks manifest and entries when true and a manifest
* exists, when false no checks are made * exists, when false no checks are made
* @param mode XXX - see ZipFile * @param mode either ZipFile.OPEN_READ or
* @exception FileNotFoundException XXX * (ZipFile.OPEN_READ | ZipFile.OPEN_DELETE)
* @exception IOException XXX * @exception FileNotFoundException if the file does not exist
* @exception IllegalArgumentException XXX * @exception IOException if another IO exception occurs while reading
* @exception IllegalArgumentException when given an illegal mode
* *
* @since 1.3 * @since 1.3
*/ */
...@@ -145,12 +147,10 @@ public class JarFile extends ZipFile { ...@@ -145,12 +147,10 @@ public class JarFile extends ZipFile {
FileNotFoundException, FileNotFoundException,
IOException, IOException,
IllegalArgumentException { IllegalArgumentException {
// XXX - For now don't use super(file, mode) super(file, mode);
this(file, verify); manifest = readManifest();
/* super(file, mode); if (verify)
manifest = readManifest(); verify();
if (verify)
verify(); */
} }
// Methods // Methods
......
...@@ -18,15 +18,35 @@ import java.io.*; ...@@ -18,15 +18,35 @@ import java.io.*;
public class ZipFile implements ZipConstants 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 public ZipFile (String fname) throws IOException
{ {
file = new RandomAccessFile(fname, "r"); this(new File(fname));
name = fname;
readDirectory ();
} }
public ZipFile (File f) throws IOException 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"); file = new RandomAccessFile(f, "r");
name = f.getName(); name = f.getName();
readDirectory (); readDirectory ();
...@@ -107,6 +127,8 @@ public class ZipFile implements ZipConstants ...@@ -107,6 +127,8 @@ public class ZipFile implements ZipConstants
file.close(); file.close();
entries = null; entries = null;
numEntries = 0; numEntries = 0;
if (delete_on_close != null)
delete_on_close.delete();
} }
public ZipEntry getEntry(String name) public ZipEntry getEntry(String name)
...@@ -148,6 +170,10 @@ public class ZipFile implements ZipConstants ...@@ -148,6 +170,10 @@ public class ZipFile implements ZipConstants
return numEntries; return numEntries;
} }
protected void finalize () throws IOException {
close();
}
private int readu2 () throws IOException private int readu2 () throws IOException
{ {
int byte0 = file.read(); int byte0 = file.read();
...@@ -173,6 +199,9 @@ public class ZipFile implements ZipConstants ...@@ -173,6 +199,9 @@ public class ZipFile implements ZipConstants
int numEntries; int numEntries;
RandomAccessFile file; RandomAccessFile file;
String name; String name;
/** File to delete on close or null. */
File delete_on_close;
} }
final class ZipEnumeration implements java.util.Enumeration final class ZipEnumeration implements java.util.Enumeration
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment