From d8b407bb63d10d31d6cf91b29ed71d3627c4a7a5 Mon Sep 17 00:00:00 2001 From: Robert Davies Date: Mon, 3 Mar 2008 07:14:39 +0000 Subject: [PATCH] Added copy file method git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@632961 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/activemq/util/IOHelper.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java b/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java index 70b8c8f499..452bca3a11 100644 --- a/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java @@ -17,7 +17,12 @@ package org.apache.activemq.util; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; /** * @version $Revision$ @@ -25,6 +30,7 @@ import java.io.IOException; public final class IOHelper { protected static final int MAX_DIR_NAME_LENGTH; protected static final int MAX_FILE_NAME_LENGTH; + private static final int DEFAULT_BUFFER_SIZE = 4096; private IOHelper() { } @@ -143,6 +149,23 @@ public final class IOHelper { } } + public static void copyFile(File src, File dest) throws IOException { + FileInputStream fileSrc = new FileInputStream(src); + FileOutputStream fileDest = new FileOutputStream(dest); + copyInputStream(fileSrc, fileDest); + } + + public static void copyInputStream(InputStream in, OutputStream out) throws IOException { + byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; + int len = in.read(buffer); + while (len >= 0) { + out.write(buffer, 0, len); + len = in.read(buffer); + } + in.close(); + out.close(); + } + static { MAX_DIR_NAME_LENGTH = Integer.valueOf(System.getProperty("MaximumDirNameLength","200")).intValue(); MAX_FILE_NAME_LENGTH = Integer.valueOf(System.getProperty("MaximumFileNameLength","64")).intValue();