commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r543777 - /jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
Date Sat, 02 Jun 2007 19:54:38 GMT
Author: oheger
Date: Sat Jun  2 12:54:37 2007
New Revision: 543777

URL: http://svn.apache.org/viewvc?view=rev&rev=543777
Log:
Changed AbstractFileConfiguration.save(URL) to always close the output stream

Modified:
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java?view=diff&rev=543777&r1=543776&r2=543777
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
Sat Jun  2 12:54:37 2007
@@ -431,6 +431,7 @@
         else
         {
             // for non file URLs save through an URLConnection
+            OutputStream out = null;
             try
             {
                 URLConnection connection = url.openConnection();
@@ -443,7 +444,8 @@
                     conn.setRequestMethod("PUT");
                 }
 
-                save(connection.getOutputStream());
+                out = connection.getOutputStream();
+                save(out);
 
                 // check the response code for http URLs and throw an exception if an error
occured
                 if (connection instanceof HttpURLConnection)
@@ -459,6 +461,10 @@
             {
                 throw new ConfigurationException("Could not save to URL " + url, e);
             }
+            finally
+            {
+                closeSilent(out);
+            }
         }
     }
 
@@ -488,18 +494,7 @@
         }
         finally
         {
-            // close the output stream
-            try
-            {
-                if (out != null)
-                {
-                    out.close();
-                }
-            }
-            catch (IOException e)
-            {
-                getLogger().warn("Could not close output stream", e);
-            }
+            closeSilent(out);
         }
     }
 
@@ -999,5 +994,27 @@
     private void initReloadingStrategy()
     {
         setReloadingStrategy(new InvariantReloadingStrategy());
+    }
+
+    /**
+     * A helper method for closing an output stream. Occurring exceptions will
+     * be ignored.
+     *
+     * @param out the output stream to be closed (may be <b>null</b>)
+     * @since 1.5
+     */
+    private void closeSilent(OutputStream out)
+    {
+        try
+        {
+            if (out != null)
+            {
+                out.close();
+            }
+        }
+        catch (IOException e)
+        {
+            getLogger().warn("Could not close output stream", e);
+        }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message