ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maart...@apache.org
Subject svn commit: r799100 - /ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/BasicURLHandler.java
Date Wed, 29 Jul 2009 22:23:14 GMT
Author: maartenc
Date: Wed Jul 29 22:23:14 2009
New Revision: 799100

URL: http://svn.apache.org/viewvc?rev=799100&view=rev
Log:
Simplified the code a bit (the inputstream will also be closed in the disconnect() method)

Modified:
    ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/BasicURLHandler.java

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/BasicURLHandler.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/BasicURLHandler.java?rev=799100&r1=799099&r2=799100&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/BasicURLHandler.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/BasicURLHandler.java Wed Jul 29 22:23:14
2009
@@ -113,7 +113,6 @@
 
     public InputStream openStream(URL url) throws IOException {
         URLConnection conn = null;
-        InputStream inStream = null;
         try {
             url = normalizeToURL(url);
             conn = url.openConnection();
@@ -126,7 +125,7 @@
                                 + " See log for more detail.");
                 }
             }
-            inStream = conn.getInputStream();
+            InputStream inStream  = conn.getInputStream();
             ByteArrayOutputStream outStream = new ByteArrayOutputStream();
 
             byte[] buffer = new byte[BUFFER_SIZE];
@@ -136,10 +135,6 @@
             }
             return new ByteArrayInputStream(outStream.toByteArray());
         } finally {
-            if (inStream != null) {
-                inStream.close();
-            }
-
             disconnect(conn);
         }
     }
@@ -238,23 +233,36 @@
     private void readResponseBody(HttpURLConnection conn) {
         byte[] buffer = new byte[BUFFER_SIZE];
         
+        InputStream inStream = null;
         try {
-            InputStream inStream = conn.getInputStream();
+            inStream = conn.getInputStream();
             while (inStream.read(buffer) > 0) {
             }
-            inStream.close();
         } catch (IOException e) {
             // ignore
+        } finally {
+            if (inStream != null) {
+                try {
+                    inStream.close();
+                } catch (IOException e) {
+                    // ignore
+                }
+            }
         }
         
-        InputStream errStream = ((HttpURLConnection) conn).getErrorStream();
+        InputStream errStream = conn.getErrorStream();
         if (errStream != null) {
             try {
                 while (errStream.read(buffer) > 0) {
                 }
-                errStream.close();
             } catch (IOException e) {
                 // ignore
+            } finally {
+                try {
+                    errStream.close();                
+                } catch (IOException e) {
+                    // ignore
+                }
             }
         }
     }



Mime
View raw message