From fb52e7ecab0f6b6d2200c1765892d93043d81500 Mon Sep 17 00:00:00 2001 From: Robert Gemmell Date: Mon, 17 Aug 2009 15:49:50 +0000 Subject: QPID-2040: add a copy method to FileUtils that throws checked exceptions instead of wrapping as them runtime exceptions git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@805016 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/org/apache/qpid/util/FileUtils.java | 49 ++++++++++++++-------- 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'java/common/src') 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 515c849290..7ba38f4743 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 @@ -196,24 +196,7 @@ public class FileUtils { try { - InputStream in = new FileInputStream(src); - if (!dst.exists()) - { - dst.createNewFile(); - } - - OutputStream 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); - } - - in.close(); - out.close(); + copyCheckedEx(src, dst); } catch (IOException e) { @@ -221,6 +204,36 @@ public class FileUtils } } + /** + * Copies the specified source file to the specified destination file. If the destination file does not exist, + * it is created. + * + * @param src The source file name. + * @param dst The destination file name. + * @throws IOException + */ + public static void copyCheckedEx(File src, File dst) throws IOException + { + InputStream in = new FileInputStream(src); + if (!dst.exists()) + { + dst.createNewFile(); + } + + OutputStream 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); + } + + in.close(); + out.close(); + } + /* * Deletes a given file */ -- cgit v1.2.1