summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorRobert Gemmell <robbie@apache.org>2009-08-17 15:49:50 +0000
committerRobert Gemmell <robbie@apache.org>2009-08-17 15:49:50 +0000
commitfb52e7ecab0f6b6d2200c1765892d93043d81500 (patch)
treef5e1c95d64714b14fe1084abb440f23ce5990eaf /java
parent82e90f9b004351242073495e2b7d0498ca4ce6d7 (diff)
downloadqpid-python-fb52e7ecab0f6b6d2200c1765892d93043d81500.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/qpid@805016 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
-rw-r--r--java/common/src/main/java/org/apache/qpid/util/FileUtils.java49
1 files changed, 31 insertions, 18 deletions
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
*/