summaryrefslogtreecommitdiff
path: root/java/common/src/main
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2008-10-08 10:52:57 +0000
committerMartin Ritchie <ritchiem@apache.org>2008-10-08 10:52:57 +0000
commitb10b0eb92315a9dbc01ccd07444f520022f46dc3 (patch)
tree81d8c27469479cd5deb50ca567bbd31c774340a3 /java/common/src/main
parentc0a96d4e35e1dd3360bb5906fe5adfc70921fa2e (diff)
downloadqpid-python-b10b0eb92315a9dbc01ccd07444f520022f46dc3.tar.gz
QPID-1268 : Improved cleanup and fixed bug in FileUtils.readFileAsString() where it did not close the file.. hence the failures on windows machines in FileUtilsTest
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@702804 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/common/src/main')
-rw-r--r--java/common/src/main/java/org/apache/qpid/util/FileUtils.java36
1 files changed, 25 insertions, 11 deletions
diff --git a/java/common/src/main/java/org/apache/qpid/util/FileUtils.java b/java/common/src/main/java/org/apache/qpid/util/FileUtils.java
index 883373ba35..3e13259ee3 100644
--- a/java/common/src/main/java/org/apache/qpid/util/FileUtils.java
+++ b/java/common/src/main/java/org/apache/qpid/util/FileUtils.java
@@ -46,16 +46,30 @@ public class FileUtils
{
BufferedInputStream is = null;
- try
- {
- is = new BufferedInputStream(new FileInputStream(filename));
- }
- catch (FileNotFoundException e)
- {
- throw new RuntimeException(e);
- }
+ try{
+ try
+ {
+ is = new BufferedInputStream(new FileInputStream(filename));
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new RuntimeException(e);
+ }
- return readStreamAsString(is);
+ return readStreamAsString(is);
+ }finally {
+ if (is != null)
+ {
+ try
+ {
+ is.close();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ }
}
/**
@@ -230,14 +244,14 @@ public class FileUtils
*/
public static boolean delete(File file, boolean recursive)
{
- boolean success=true;
+ boolean success = true;
if (file.isDirectory())
{
if (recursive)
{
for (File subFile : file.listFiles())
- {
+ {
success = delete(subFile, true) & success ;
}