harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r475338 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java test/java/tests/api/java/net/JarURLConnectionTest.java
Date Wed, 15 Nov 2006 18:00:43 GMT
Author: pyang
Date: Wed Nov 15 10:00:42 2006
New Revision: 475338

URL: http://svn.apache.org/viewvc?view=rev&rev=475338
Log:
Apply patch for HARMONY-2138 ([classlib][luni]different behavior when delete file)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/JarURLConnectionTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java?view=diff&rev=475338&r1=475337&r2=475338
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java
Wed Nov 15 10:00:42 2006
@@ -21,6 +21,7 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
+import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.ref.ReferenceQueue;
@@ -302,7 +303,7 @@
 			return jarInput;
 		if (jarEntry == null)
 			throw new IOException(Msg.getString("K00fc")); //$NON-NLS-1$
-		return jarInput = jarFile.getInputStream(jarEntry);
+		return jarInput = new JarURLConnectionInputStream(jarFile.getInputStream(jarEntry),jarFile);
 	}
 
 	/**
@@ -397,4 +398,35 @@
 			}
 		}
 	}
+    
+    private class JarURLConnectionInputStream extends FilterInputStream {
+        InputStream inputStream;
+        JarFile jarFile;
+
+        protected JarURLConnectionInputStream(InputStream in, JarFile file) {
+            super(in);
+            inputStream = in;
+            jarFile = file;
+        }
+
+        public void close() throws IOException {
+            super.close();
+            if (!useCaches) {
+                connected = false;
+                jarFile.close();
+            }
+        }
+       
+        public int read() throws IOException {
+            return inputStream.read();
+        }
+
+        public int read(byte[] buf, int off, int nbytes) throws IOException {
+            return inputStream.read(buf, off, nbytes);
+        }
+
+        public long skip(long nbytes) throws IOException {
+            return inputStream.skip(nbytes);
+        }
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/JarURLConnectionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/JarURLConnectionTest.java?view=diff&rev=475338&r1=475337&r2=475338
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/JarURLConnectionTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/JarURLConnectionTest.java
Wed Nov 15 10:00:42 2006
@@ -17,13 +17,16 @@
 
 package tests.api.java.net;
 
+import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.JarURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.jar.JarEntry;
 import java.util.jar.JarOutputStream;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
@@ -166,6 +169,31 @@
         assertEquals("Returned incorrect Attributes", "1.0", a
                 .get(java.util.jar.Attributes.Name.MANIFEST_VERSION));
     }
+    
+    /**
+     * @tests java.net.JarURLConnection#getInputStream()
+     */
+    public void test_getInputStream_DeleteJarFileUsingURLConnection()
+            throws Exception {
+        String jarFileName = "file.jar";
+        String entry = "text.txt";
+        File file = new File(jarFileName);
+        FileOutputStream jarFile = new FileOutputStream(jarFileName);
+        JarOutputStream out = new JarOutputStream(new BufferedOutputStream(
+                jarFile));
+        JarEntry jarEntry = new JarEntry(entry);
+        out.putNextEntry(jarEntry);
+        out.write(new byte[] { 'a', 'b', 'c' });
+        out.close();
+
+        URL url = new URL("jar:file:" + jarFileName + "!/" + entry);
+        URLConnection conn = url.openConnection();
+        conn.setUseCaches(false);
+        InputStream is = conn.getInputStream();
+        is.close();
+        assertTrue(file.delete());
+    }
+
 
 	protected void setUp() {
 	}



Mime
View raw message