Author: davsclaus Date: Tue Jul 26 07:14:46 2011 New Revision: 1151000 URL: http://svn.apache.org/viewvc?rev=1151000&view=rev Log: CAMEL-4265: Closing file resource after loading properties. Thanks to Edge Wang for the patch.
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java?rev=1151000&r1=1150999&r2=1151000&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java Tue Jul 26 07:14:46 2011 @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Properties; import org.apache.camel.CamelContext; +import org.apache.camel.util.IOHelper; import org.apache.camel.util.ObjectHelper; /** @@ -61,25 +62,42 @@ public class DefaultPropertiesResolver i } protected Properties loadPropertiesFromFilePath(CamelContext context, String path) throws IOException { + Properties answer = null; + if (path.startsWith("file:")) { path = ObjectHelper.after(path, "file:"); } + InputStream is = new FileInputStream(path); - Properties answer = new Properties(); - answer.load(is); + try { + answer = new Properties(); + answer.load(is); + } finally { + IOHelper.close(is); + } + return answer; } protected Properties loadPropertiesFromClasspath(CamelContext context, String path) throws IOException { + Properties answer = null; + if (path.startsWith("classpath:")) { path = ObjectHelper.after(path, "classpath:"); } + InputStream is = context.getClassResolver().loadResourceAsStream(path); if (is == null) { throw new FileNotFoundException("Properties file " + path + " not found in classpath"); } - Properties answer = new Properties(); - answer.load(is); + + try { + answer = new Properties(); + answer.load(is); + } finally { + IOHelper.close(is); + } + return answer; }