cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r1142599 - /cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/URLConnectionUtils.java
Date Mon, 04 Jul 2011 09:52:23 GMT
Author: reinhard
Date: Mon Jul  4 09:52:23 2011
New Revision: 1142599

URL: http://svn.apache.org/viewvc?rev=1142599&view=rev
Log:
reduce code duplication

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

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/URLConnectionUtils.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/URLConnectionUtils.java?rev=1142599&r1=1142598&r2=1142599&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/URLConnectionUtils.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/URLConnectionUtils.java
Mon Jul  4 09:52:23 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.cocoon.pipeline.util;
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -37,7 +38,7 @@ public abstract class URLConnectionUtils
         if (urlConnection == null) {
             return;
         }
-    	
+
         if (urlConnection.getDoInput()) {
             InputStream inputStream = null;
             try {
@@ -45,13 +46,7 @@ public abstract class URLConnectionUtils
             } catch (IOException e) {
                 LOG.warn("Can't close input stream from " + urlConnection.getURL(), e);
             } finally {
-                if (inputStream != null) {
-                    try {
-                        inputStream.close();
-                    } catch (IOException e) {
-                        LOG.warn("Can't close input stream from " + urlConnection.getURL(),
e);
-                    }
-                }
+                close(urlConnection, inputStream);
             }
         }
 
@@ -62,13 +57,17 @@ public abstract class URLConnectionUtils
             } catch (IOException e) {
                 LOG.warn("Can't close output stream to " + urlConnection.getURL(), e);
             } finally {
-                if (outputStream != null) {
-                    try {
-                        outputStream.close();
-                    } catch (IOException e) {
-                        LOG.warn("Can't close input stream to " + urlConnection.getURL(),
e);
-                    }
-                }
+                close(urlConnection, outputStream);
+            }
+        }
+    }
+
+    private static void close(URLConnection urlConnection, Closeable closeable) {
+        if (closeable != null) {
+            try {
+                closeable.close();
+            } catch (IOException e) {
+                LOG.warn("Can't close stream (" + closeable.getClass().getSimpleName() +
"): " + urlConnection.getURL(), e);
             }
         }
     }



Mime
View raw message