cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r675935 - /cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/URLConnectionUtils.java
Date Fri, 11 Jul 2008 12:27:35 GMT
Author: reinhard
Date: Fri Jul 11 05:27:34 2008
New Revision: 675935

URL: http://svn.apache.org/viewvc?rev=675935&view=rev
Log:
add a method to close url connections quietly

Modified:
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/URLConnectionUtils.java

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/URLConnectionUtils.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/URLConnectionUtils.java?rev=675935&r1=675934&r2=675935&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/URLConnectionUtils.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/URLConnectionUtils.java
Fri Jul 11 05:27:34 2008
@@ -18,6 +18,7 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.URLConnection;
 
 import org.apache.cocoon.corona.pipeline.component.XMLConsumer;
@@ -26,21 +27,40 @@
 
 public abstract class URLConnectionUtils {
 
-    private static final Log LOGGER = LogFactory.getLog(URLConnectionUtils.class);
+    private static final Log LOG = LogFactory.getLog(URLConnectionUtils.class);
 
     public static void toSax(URLConnection urlConnection, XMLConsumer xmlConsumer) {
-        InputStream inputStream = null;
         try {
-            XMLUtils.toSax(urlConnection.getInputStream(), xmlConsumer);
+            InputStream inputStream = urlConnection.getInputStream();
+            XMLUtils.toSax(inputStream, xmlConsumer);
+            inputStream.close();
         } catch (Exception e) {
             throw new RuntimeException("Can't parse url connection " + urlConnection.getURL(),
e);
-        } finally {
-            if (inputStream != null) {
-                try {
+        }
+    }
+
+    public static void closeQuietly(URLConnection urlConnection) {
+        if (urlConnection.getDoInput()) {
+            try {
+                InputStream inputStream = urlConnection.getInputStream();
+
+                if (inputStream != null) {
                     inputStream.close();
-                } catch (IOException e) {
-                    LOGGER.error("Error while closing input stream on " + urlConnection.getURL(),
e);
                 }
+            } catch (IOException e) {
+                LOG.warn("Can't close input stream from " + urlConnection.getURL(), e);
+            }
+        }
+
+        if (urlConnection.getDoOutput()) {
+            try {
+                OutputStream outputStream = urlConnection.getOutputStream();
+
+                if (outputStream != null) {
+                    outputStream.close();
+                }
+            } catch (IOException e) {
+                LOG.warn("Can't close output stream to " + urlConnection.getURL(), e);
             }
         }
     }



Mime
View raw message