You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/09/30 04:33:49 UTC
[5/6] git commit: Use LoaderUtil.findResources.
Use LoaderUtil.findResources.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/20c80a94
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/20c80a94
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/20c80a94
Branch: refs/heads/master
Commit: 20c80a9407491b106bc0fb74c24c3a1a10a0fcbe
Parents: d80c6a2
Author: Matt Sicker <ma...@apache.org>
Authored: Mon Sep 29 21:32:43 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Mon Sep 29 21:32:43 2014 -0500
----------------------------------------------------------------------
.../logging/log4j/util/PropertiesUtil.java | 32 ++++++++------------
1 file changed, 12 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/20c80a94/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
index 3d74db5..04e94e1 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
@@ -19,7 +19,6 @@ package org.apache.logging.log4j.util;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import java.util.Enumeration;
import java.util.Properties;
import org.apache.logging.log4j.Logger;
@@ -86,32 +85,25 @@ public final class PropertiesUtil {
* @param propertiesFileName the location of properties file to load
*/
public PropertiesUtil(final String propertiesFileName) {
- final ClassLoader loader = LoaderUtil.getThreadContextClassLoader();
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
- final
- Properties properties = new Properties();
+ final Properties properties = new Properties();
+ for (final URL url : LoaderUtil.findResources(propertiesFileName)) {
+ InputStream in = null;
try {
- final Enumeration<URL> enumeration = loader.getResources(propertiesFileName);
- while (enumeration.hasMoreElements()) {
- final URL url = enumeration.nextElement();
- final InputStream in = url.openStream();
+ in = url.openStream();
+ properties.load(in);
+ } catch (final IOException ioe) {
+ LOGGER.error("Unable to read {}", url.toString(), ioe);
+ } finally {
+ if (in != null) {
try {
- properties.load(in);
+ in.close();
} catch (final IOException ioe) {
- LOGGER.error("Unable to read {}", url.toString(), ioe);
- } finally {
- try {
- in.close();
- } catch (final IOException ioe) {
- LOGGER.error("Unable to close {}", url.toString(), ioe);
- }
+ LOGGER.error("Unable to close {}", url.toString(), ioe);
}
-
}
-
- } catch (final IOException ioe) {
- LOGGER.error("Unable to access {}", propertiesFileName, ioe);
}
+ }
this.props = properties;
}