oltu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1003000 - /incubator/amber/trunk/spec-api/src/main/java/org/apache/amber/OAuth.java
Date Thu, 30 Sep 2010 10:44:50 GMT
Author: simonetripodi
Date: Thu Sep 30 10:44:50 2010
New Revision: 1003000

URL: http://svn.apache.org/viewvc?rev=1003000&view=rev
Log:
extracted method to close quietly Cloaseable instances

Modified:
    incubator/amber/trunk/spec-api/src/main/java/org/apache/amber/OAuth.java

Modified: incubator/amber/trunk/spec-api/src/main/java/org/apache/amber/OAuth.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/spec-api/src/main/java/org/apache/amber/OAuth.java?rev=1003000&r1=1002999&r2=1003000&view=diff
==============================================================================
--- incubator/amber/trunk/spec-api/src/main/java/org/apache/amber/OAuth.java (original)
+++ incubator/amber/trunk/spec-api/src/main/java/org/apache/amber/OAuth.java Thu Sep 30 10:44:50
2010
@@ -28,6 +28,8 @@ import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
+
+import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -110,16 +112,20 @@ public final class OAuth {
         // TODO avoid classloader memory leaks?
         ClassLoader loader = Thread.currentThread().getContextClassLoader();
 
+        InputStream inputStream = null;
         try {
             Enumeration<URL> resources = loader.getResources(PROPERTIES_XML);
             while (resources.hasMoreElements()) {
                 // TODO specify classloader search order manually?
                 // Load the first resource
                 URL resource = resources.nextElement();
-                properties.loadFromXML(resource.openStream());
+                inputStream = resource.openStream();
+                properties.loadFromXML(inputStream);
             }
         } catch (IOException e) {
             throw new OAuthRuntimeException(e);
+        } finally {
+            closeQuietly(inputStream);
         }
 
         return createFactory(version, properties);
@@ -213,13 +219,7 @@ public final class OAuth {
                             // TODO warn of error here, in log?
                             e.printStackTrace();
                         } finally {
-                            if (inputStream != null) {
-                                try {
-                                    inputStream.close();
-                                } catch (IOException e) {
-                                    // close quietly
-                                }
-                            }
+                            closeQuietly(inputStream);
                         }
                     }
                 } catch (IOException e) {
@@ -243,4 +243,14 @@ public final class OAuth {
         throw new OAuthRuntimeException(OAuthFactory.class.getName() + " implementation not
found.");
     }
 
+    private static void closeQuietly(Closeable closeable) {
+        if (closeable != null) {
+            try {
+                closeable.close();
+            } catch (Exception e) {
+                // close quietly
+            }
+        }
+    }
+
 }



Mime
View raw message