From e27df5d4f5047ae54608161cbca63d0ed2017280 Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Tue, 10 Jul 2007 19:55:32 +0000
Subject: [PATCH] Make sure streams have been closed in copy operation should an exception be thrown.
---
opends/src/quicksetup/org/opends/quicksetup/util/FileManager.java | 24 +++++++++++++++++++-----
1 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/opends/src/quicksetup/org/opends/quicksetup/util/FileManager.java b/opends/src/quicksetup/org/opends/quicksetup/util/FileManager.java
index 8b3c1f9..f8e572e 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/util/FileManager.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/util/FileManager.java
@@ -469,17 +469,16 @@
LOG.log(Level.INFO, "copying file '" +
objectFile.getAbsolutePath() + "' to '" +
destination.getAbsolutePath() + "'");
+ FileInputStream fis = null;
+ FileOutputStream fos = null;
try {
- FileInputStream fis = new FileInputStream(objectFile);
- FileOutputStream fos = new FileOutputStream(destination);
+ fis = new FileInputStream(objectFile);
+ fos = new FileOutputStream(destination);
byte[] buf = new byte[1024];
int i;
while ((i = fis.read(buf)) != -1) {
fos.write(buf, 0, i);
}
- fis.close();
- fos.close();
-
if (destination.exists()) {
// TODO: set the file's permissions. This is made easier in
// Java 1.6 but until then use the TestUtilities methods
@@ -502,6 +501,21 @@
throw new ApplicationException(
ApplicationException.Type.FILE_SYSTEM_ERROR,
errMsg, null);
+ } finally {
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ // ignore;
+ }
+ }
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (IOException e) {
+ // ignore;
+ }
+ }
}
} else {
String errMsg = getMsg("error-copying-file", args);
--
Gitblit v1.10.0