diff options
author | Robert Gemmell <robbie@apache.org> | 2009-08-17 15:49:50 +0000 |
---|---|---|
committer | Robert Gemmell <robbie@apache.org> | 2009-08-17 15:49:50 +0000 |
commit | f8d3c9d43f8a3f64acb029958030f2abd3b6b6a3 (patch) | |
tree | 8bab5448f7bf611d0a1899ce7abe7381a5211d22 | |
parent | 032461d73cd6419fef26c5a66dd5e33e6f2ef49d (diff) | |
download | qpid-python-f8d3c9d43f8a3f64acb029958030f2abd3b6b6a3.tar.gz |
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@805016 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java b/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java index 515c849290..7ba38f4743 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java +++ b/qpid/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 */ |