This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: ZipFile and OPEN_DELETE


I'm checking this in to libgcj and classpath.

We can implement ZipFile.OPEN_DELETE these days using
File.deleteOnExit.  This isn't the very best approach, in that the
file stays around until the VM exits, but it is better than leaving
it lying there forever.

The actual Classpath patch differs slightly, as Classpath apparently
has a different jar url provider implementation.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* gnu/java/net/protocol/jar/Connection.java (getJarFile): Open
	jar file with OPEN_DELETE.
	* java/util/zip/ZipFile.java (ZipFile): Call deleteOnExit when
	OPEN_DELETE is used.

Index: gnu/java/net/protocol/jar/Connection.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/net/protocol/jar/Connection.java,v
retrieving revision 1.7
diff -u -r1.7 Connection.java
--- gnu/java/net/protocol/jar/Connection.java 23 Jul 2004 01:21:40 -0000 1.7
+++ gnu/java/net/protocol/jar/Connection.java 10 Feb 2005 02:11:46 -0000
@@ -1,5 +1,5 @@
 /* Connection - jar url connection for java.net
-   Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002, 2003, 2005 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -222,9 +222,8 @@
 	  fos.write(buf, 0, len);
         fos.close();
 	// Always verify the Manifest, open read only and delete when done.
-	// XXX ZipFile.OPEN_DELETE not yet implemented.
-	// jf = new JarFile(f, true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE);
-	jar_file = new JarFile (f, true, ZipFile.OPEN_READ);
+	jar_file = new JarFile (f, true,
+				ZipFile.OPEN_READ | ZipFile.OPEN_DELETE);
       }
 
     return jar_file;
Index: java/util/zip/ZipFile.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/zip/ZipFile.java,v
retrieving revision 1.28
diff -u -r1.28 ZipFile.java
--- java/util/zip/ZipFile.java 7 Nov 2004 01:25:48 -0000 1.28
+++ java/util/zip/ZipFile.java 10 Feb 2005 02:11:46 -0000
@@ -1,5 +1,5 @@
 /* ZipFile.java --
-   Copyright (C) 2001, 2002, 2003, 2004  Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002, 2003, 2004, 2005  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -117,8 +117,6 @@
    * 
    * The contents of the zip file will be accessible until it is closed.
    *
-   * The OPEN_DELETE mode is currently unimplemented in this library
-   * 
    * @since JDK1.3
    * @param mode Must be one of OPEN_READ or OPEN_READ | OPEN_DELETE
    *
@@ -128,11 +126,10 @@
    */
   public ZipFile(File file, int mode) throws ZipException, IOException
   {
+    if (mode != OPEN_READ && mode != (OPEN_READ | OPEN_DELETE))
+      throw new IllegalArgumentException("invalid mode");
     if ((mode & OPEN_DELETE) != 0)
-      {
-	throw new IllegalArgumentException
-	  ("OPEN_DELETE mode not supported yet in java.util.zip.ZipFile");
-      }
+      file.deleteOnExit();
     this.raf = new RandomAccessFile(file, "r");
     this.name = file.getPath();
   }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]