summaryrefslogtreecommitdiff
path: root/qadevOOo/runner/helper/FileTools.java
diff options
context:
space:
mode:
authorRobert Antoni Buj i Gelonch <robert.buj@gmail.com>2014-10-13 13:20:47 +0200
committerNoel Grandin <noelgrandin@gmail.com>2014-10-14 07:15:41 +0000
commita2c481457cd2d03263054a5fefe80da316e09a44 (patch)
tree5b8717ae1fdfd55b5c3c56410408acd92a94ef42 /qadevOOo/runner/helper/FileTools.java
parentfa6ac05beaaf1160c205e40099b99f0ed0efb131 (diff)
runner: finally block to ensure that a resource is closed (Prior to Java SE 7)
http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html Change-Id: I5ecefd3e5bf84fea2a8735a44236ed4c86b440c4 Reviewed-on: https://gerrit.libreoffice.org/11950 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'qadevOOo/runner/helper/FileTools.java')
-rw-r--r--qadevOOo/runner/helper/FileTools.java28
1 files changed, 19 insertions, 9 deletions
diff --git a/qadevOOo/runner/helper/FileTools.java b/qadevOOo/runner/helper/FileTools.java
index cede7c46059d..4bcee70a52ce 100644
--- a/qadevOOo/runner/helper/FileTools.java
+++ b/qadevOOo/runner/helper/FileTools.java
@@ -80,17 +80,27 @@ public class FileTools {
* @throws java.io.IOException throws java.io.IOException if something failes
*/
public static void copyFile(File src, File dst) throws java.io.IOException {
- InputStream in = new FileInputStream(src);
- OutputStream out = new FileOutputStream(dst);
+ InputStream in = null;
+ OutputStream out = null;
+ try {
+ in = new FileInputStream(src);
+ try {
+ out = new FileOutputStream(dst);
- // Transfer bytes from in to out
- byte[] buf = new byte[1024];
- int len;
- while ((len = in.read(buf)) > 0) {
- out.write(buf, 0, len);
+ // Transfer bytes from in to out
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ } finally {
+ if (out != null)
+ out.close();
+ }
+ } finally {
+ if (in != null)
+ in.close();
}
- in.close();
- out.close();
}