activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajdav...@apache.org
Subject svn commit: r632961 - /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java
Date Mon, 03 Mar 2008 07:14:40 GMT
Author: rajdavies
Date: Sun Mar  2 23:14:39 2008
New Revision: 632961

URL: http://svn.apache.org/viewvc?rev=632961&view=rev
Log:
Added copy file method

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java?rev=632961&r1=632960&r2=632961&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java Sun
Mar  2 23:14:39 2008
@@ -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 @@
 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() {
     }
 
@@ -141,6 +147,23 @@
         if (!src.renameTo(new File(targetDirectory, src.getName()))) {
             throw new IOException("Failed to move " + src + " to " + targetDirectory);
         }
+    }
+    
+    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 {



Mime
View raw message