Author: lhein
Date: Mon Dec  8 05:40:58 2008
New Revision: 724345

URL: http://svn.apache.org/viewvc?rev=724345&view=rev
Log:
helper methods for determining if a file is fully copied and available or if 
the copy process is still running
actually it checks the file size with a delay of 100 millis

Modified:
    
servicemix/utils/trunk/src/main/java/org/apache/servicemix/util/FileUtil.java

Modified: 
servicemix/utils/trunk/src/main/java/org/apache/servicemix/util/FileUtil.java
URL: 
http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/util/FileUtil.java?rev=724345&r1=724344&r2=724345&view=diff
==============================================================================
--- 
servicemix/utils/trunk/src/main/java/org/apache/servicemix/util/FileUtil.java 
(original)
+++ 
servicemix/utils/trunk/src/main/java/org/apache/servicemix/util/FileUtil.java 
Mon Dec  8 05:40:58 2008
@@ -313,5 +313,36 @@
         }
     }
     
-    
+    /**
+     * checks whether a file is fully transmitted or still being copied
+     * 
+     * @param path      the full file path
+     * @returns         true if the file size didn't change for 100 millis 
+     */
+    public static boolean isFileFullyAvailable(String path) {
+        return isFileFullyAvailable(new File(path));
+    }
+
+    /**
+     * checks whether a file is fully transmitted or still being copied
+     * 
+     * @param file      the file to check
+     * @returns         true if the file size didn't change for 100 millis 
+     */
+    public static boolean isFileFullyAvailable(File file) {
+        // First check to see if the file is still growing
+        long targetLength = file.length();
+        try {
+            Thread.sleep(100);
+        } catch (InterruptedException e) {
+            //Do nothing
+        }
+        long target2Length = file.length();
+
+        if (targetLength != target2Length) {
+            return false;
+        }
+        
+        return true;
+    }
 }
\ No newline at end of file


Reply via email to