You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ivy-commits@incubator.apache.org by xa...@apache.org on 2006/12/17 17:06:26 UTC

svn commit: r488010 - /incubator/ivy/trunk/src/java/fr/jayasoft/ivy/url/BasicURLHandler.java

Author: xavier
Date: Sun Dec 17 09:06:26 2006
New Revision: 488010

URL: http://svn.apache.org/viewvc?view=rev&rev=488010
Log:
review disconnection: workaround for sun jre bug in file url connection

Modified:
    incubator/ivy/trunk/src/java/fr/jayasoft/ivy/url/BasicURLHandler.java

Modified: incubator/ivy/trunk/src/java/fr/jayasoft/ivy/url/BasicURLHandler.java
URL: http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/fr/jayasoft/ivy/url/BasicURLHandler.java?view=diff&rev=488010&r1=488009&r2=488010
==============================================================================
--- incubator/ivy/trunk/src/java/fr/jayasoft/ivy/url/BasicURLHandler.java (original)
+++ incubator/ivy/trunk/src/java/fr/jayasoft/ivy/url/BasicURLHandler.java Sun Dec 17 09:06:26 2006
@@ -77,13 +77,11 @@
         } catch (IOException e) {
             Message.error("Server access Error: "+e.getMessage()+" url="+url);
         } finally {
-            if (con instanceof HttpURLConnection) {
-                ((HttpURLConnection)con).disconnect();
-            }
+            disconnect(con);
         }
         return UNAVAILABLE;
     }
-    
+
     public InputStream openStream(URL url) throws IOException {
         URLConnection conn = null;
         InputStream inStream = null;
@@ -104,12 +102,7 @@
                 inStream.close();
             }
             
-            if (conn != null) {
-                if (conn instanceof HttpURLConnection) {
-                    //System.out.println("Closing HttpURLConnection");
-                    ((HttpURLConnection) conn).disconnect();
-                }
-            }
+            disconnect(conn);
         }
     }
     public void download(URL src, File dest, CopyProgressListener l) throws IOException {
@@ -124,12 +117,21 @@
             }
         }
         finally {
-            if (srcConn != null) {
-                if (srcConn instanceof HttpURLConnection) {
-                    //System.out.println("Closing HttpURLConnection");
-                    ((HttpURLConnection) srcConn).disconnect();
-                }
-            }
+            disconnect(srcConn);
         }
     }
+
+    private void disconnect(URLConnection con) {
+		if (con instanceof HttpURLConnection) {
+		    ((HttpURLConnection)con).disconnect();
+		} else if (con != null && "sun.net.www.protocol.file.FileURLConnection".equals(con.getClass().getName())) {
+			// ugly fix for a sun jre bug:
+			// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4257700
+			//
+			// getting header info on the fileurlconnection opens the connection, 
+			// which opens a file input stream without closing it.
+			try {con.getInputStream().close();} catch (IOException e) {}
+		}
+	}
+    
 }