From b10b0eb92315a9dbc01ccd07444f520022f46dc3 Mon Sep 17 00:00:00 2001 From: Martin Ritchie Date: Wed, 8 Oct 2008 10:52:57 +0000 Subject: 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 --- .../main/java/org/apache/qpid/util/FileUtils.java | 36 +++++++++++++++------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'java/common/src/main') 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 ; } -- cgit v1.2.1