Re: [configuration] Closing opened input streams

2004-04-02 Thread Emmanuel Bourg
There is another stream in ClassPropertiesConfiguration if you can get a 
look Eric.

Emmanuel

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: [configuration] Closing opened input streams

2004-03-30 Thread Emmanuel Bourg
Eric Pugh wrote:

I don't know, it seems though that if we can't close the stream, should we
keep going?
Yes I think so, the configuration is usable even if the stream cannot be 
closed. It's not a fatal error, but the user has to be notified to take 
the necessary measures. We may prefer using commons-logging here instead 
of a raw stacktrace though.

Emmanuel Bourg

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: [configuration] Closing opened input streams

2004-03-29 Thread Emmanuel Bourg
I just looked at the patch :

--- PropertiesConfiguration.java28 Mar 2004 14:43:04 - 1.5
+++ PropertiesConfiguration.java28 Mar 2004 15:34:23 - 1.6
@@ -99,7 +99,9 @@
 public void load(String fileName) throws ConfigurationException
 {
 try {
-load(getPropertyStream(fileName));
+InputStream is = getPropertyStream(fileName);
+load(is);
+is.close();
 }
I think the call to the close() method should be in a finally block instead.

Emmanuel Bourg

Eric Pugh wrote:
Hi Stephen,

I think I have just resolved the problem!  Thanks for sending it.

Eric


-Original Message-
From: Stephen Colebourne [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 17, 2004 9:30 PM
To: Jakarta Commons Developers List
Subject: [configuration] Closing opened input streams
A bug was reported against [collections] ExtendedProperties
http://issues.apache.org/bugzilla/show_bug.cgi?id=27737
I found that the input stream created in the constructor was not closed. I
just checked PropertiesConfiguration, and the load() methods seem to have
the same problem.
Stephen

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: [configuration] Closing opened input streams

2004-03-29 Thread Eric Pugh
We can do that..  Just need to trap and throw the resulting IOException as a
ConfigurationException then...

Eric

 -Original Message-
 From: Emmanuel Bourg [mailto:[EMAIL PROTECTED]
 Sent: Monday, March 29, 2004 10:34 AM
 To: Jakarta Commons Developers List
 Subject: Re: [configuration] Closing opened input streams


 I just looked at the patch :

 --- PropertiesConfiguration.java  28 Mar 2004 14:43:04 - 1.5
 +++ PropertiesConfiguration.java  28 Mar 2004 15:34:23 - 1.6
 @@ -99,7 +99,9 @@
   public void load(String fileName) throws ConfigurationException
   {
   try {
 -load(getPropertyStream(fileName));
 +InputStream is = getPropertyStream(fileName);
 +load(is);
 +is.close();
   }


 I think the call to the close() method should be in a finally
 block instead.

 Emmanuel Bourg


 Eric Pugh wrote:
  Hi Stephen,
 
  I think I have just resolved the problem!  Thanks for sending it.
 
  Eric
 
 
 -Original Message-
 From: Stephen Colebourne [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, March 17, 2004 9:30 PM
 To: Jakarta Commons Developers List
 Subject: [configuration] Closing opened input streams
 
 
 A bug was reported against [collections] ExtendedProperties
 http://issues.apache.org/bugzilla/show_bug.cgi?id=27737
 
 I found that the input stream created in the constructor was
 not closed. I
 just checked PropertiesConfiguration, and the load() methods
 seem to have
 the same problem.
 
 Stephen
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 



 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [configuration] Closing opened input streams

2004-03-29 Thread Emmanuel Bourg
Eric Pugh wrote:

We can do that..  Just need to trap and throw the resulting IOException as a
ConfigurationException then...
I wouldn't throw an exception if close() fails, it doesn't prevent using 
the configuration since we have finished reading the stream at this 
point. A warning or a stack trace would be enough.

Emmanuel Bourg

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: [configuration] Closing opened input streams

2004-03-29 Thread Eric Pugh
Okay, I am thinking of this then:

public void load(String fileName) throws ConfigurationException
{
InputStream is=null;
try {
is = getPropertyStream(fileName);
load(is);
}
catch (IOException ioe){
throw new ConfigurationException(Could not load from file  +
fileName,ioe);
}
finally{
if(is !=null){
try{
is.close();
}
catch (IOException ioe2){
ioe2.printStackTrace();
}
}
}
}

I don't know, it seems though that if we can't close the stream, should we
keep going?

Eric

 -Original Message-
 From: Emmanuel Bourg [mailto:[EMAIL PROTECTED]
 Sent: Monday, March 29, 2004 1:48 PM
 To: Jakarta Commons Developers List
 Subject: Re: [configuration] Closing opened input streams


 Eric Pugh wrote:

  We can do that..  Just need to trap and throw the resulting
 IOException as a
  ConfigurationException then...

 I wouldn't throw an exception if close() fails, it doesn't prevent using
 the configuration since we have finished reading the stream at this
 point. A warning or a stack trace would be enough.

 Emmanuel Bourg

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: [configuration] Closing opened input streams

2004-03-28 Thread Eric Pugh
Hi Stephen,

I think I have just resolved the problem!  Thanks for sending it.

Eric

 -Original Message-
 From: Stephen Colebourne [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, March 17, 2004 9:30 PM
 To: Jakarta Commons Developers List
 Subject: [configuration] Closing opened input streams


 A bug was reported against [collections] ExtendedProperties
 http://issues.apache.org/bugzilla/show_bug.cgi?id=27737

 I found that the input stream created in the constructor was not closed. I
 just checked PropertiesConfiguration, and the load() methods seem to have
 the same problem.

 Stephen


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [configuration] Closing opened input streams

2004-03-22 Thread Emmanuel Bourg
I think this patch will fix the issue for [configuration].

Emmanuel Bourg

Stephen Colebourne wrote:

A bug was reported against [collections] ExtendedProperties
http://issues.apache.org/bugzilla/show_bug.cgi?id=27737
I found that the input stream created in the constructor was not closed. I
just checked PropertiesConfiguration, and the load() methods seem to have
the same problem.
Stephen

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Index: src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java
===
RCS file: 
/home/cvspublic/jakarta-commons/configuration/src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java,v
retrieving revision 1.5
diff -u -r1.5 BasePropertiesConfiguration.java
--- src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java  13 Mar 
2004 17:34:37 -  1.5
+++ src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java  22 Mar 
2004 17:58:49 -
@@ -137,7 +137,7 @@
  * Load the properties from the given input stream.
  *
  * @param input An InputStream.
- * @throws IOException
+ * @throws ConfigurationException
  */
 public void load(InputStream input)
 throws ConfigurationException
@@ -151,7 +151,7 @@
  *
  * @param input An InputStream.
  * @param enc An encoding.
- * @exception IOException
+ * @exception ConfigurationException
  */
 public synchronized void load(InputStream input, String enc)
 throws ConfigurationException
@@ -203,7 +203,18 @@
 String [] files = StringUtils.split(value, ,);
 for (int cnt = 0 ; cnt  files.length ; cnt++)
 {
-load(getPropertyStream(files[cnt].trim()));
+InputStream in = null;
+
+try {
+in = getPropertyStream(files[cnt].trim());
+load(in);
+} finally {
+try {
+if (in != null) {
+in.close();
+}
+} catch (IOException e) {}
+}
 }
 }
 }
@@ -224,7 +235,7 @@
  * properties with multiple values are saved comma seperated.
  *
  * @param filename name of the properties file
- * @throws IOException
+ * @throws ConfigurationException
  */
 public void save(String filename)
 throws ConfigurationException
Index: src/java/org/apache/commons/configuration/ClassPropertiesConfiguration.java
===
RCS file: 
/home/cvspublic/jakarta-commons/configuration/src/java/org/apache/commons/configuration/ClassPropertiesConfiguration.java,v
retrieving revision 1.5
diff -u -r1.5 ClassPropertiesConfiguration.java
--- src/java/org/apache/commons/configuration/ClassPropertiesConfiguration.java 13 Mar 
2004 17:31:40 -  1.5
+++ src/java/org/apache/commons/configuration/ClassPropertiesConfiguration.java 22 Mar 
2004 17:58:49 -
@@ -49,7 +49,7 @@
  *
  * @param baseClass The class providing the FileStream.
  * @param resource The name of the Resource.
- * @throws IOException Error while loading the properties file
+ * @throws ConfigurationException Error while loading the properties file
  */
 public ClassPropertiesConfiguration(Class baseClass, String resource)
 throws ConfigurationException
@@ -63,11 +63,22 @@
 : baseClass.getClassLoader();
 
 setIncludesAllowed(true);
+
+InputStream in = null;
+
 try {
-   load(getPropertyStream(resource));
+in = getPropertyStream(resource);
+   load(in);
 }
 catch (IOException ioe){
throw new ConfigurationException(Could not load input stream from 
resource  + resource,ioe);
+}
+finally {
+try {
+if (in != null) {
+in.close();
+}
+} catch (IOException e) {}
 }
 }
 
Index: src/java/org/apache/commons/configuration/PropertiesConfiguration.java
===
RCS file: 
/home/cvspublic/jakarta-commons/configuration/src/java/org/apache/commons/configuration/PropertiesConfiguration.java,v
retrieving revision 1.4
diff -u -r1.4 PropertiesConfiguration.java
--- src/java/org/apache/commons/configuration/PropertiesConfiguration.java  27 Feb 
2004 17:41:35 -  1.4
+++