diff src/org/dancres/blitz/disk/BackupTask.java @ 0:3dc0c5604566

Initial checkin of blitz 2.0 fcs - no installer yet.
author Dan Creswell <dan.creswell@gmail.com>
date Sat, 21 Mar 2009 11:00:06 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/dancres/blitz/disk/BackupTask.java	Sat Mar 21 11:00:06 2009 +0000
@@ -0,0 +1,68 @@
+package org.dancres.blitz.disk;
+
+import java.io.IOException;
+import java.io.File;
+
+import java.util.logging.Level;
+
+import org.dancres.io.FileCopier;
+
+class BackupTask implements Runnable {
+    private File theSourceDir;
+    private File theDestDir;
+
+    private FileCopier theCopier = new FileCopier();
+
+    private boolean isComplete = false;
+    private IOException theException = null;
+
+    BackupTask(File aSource, File aDest) {
+        theSourceDir = aSource;
+        theDestDir = aDest;
+    }
+
+    public void run() {
+        Disk.theLogger.log(Level.SEVERE, "Start backup: " + theSourceDir
+                           + ", " + theDestDir);
+
+        File[] myFiles = theSourceDir.listFiles();
+
+        Disk.theLogger.log(Level.SEVERE, "Number of files: " +
+                           myFiles.length);
+
+        try {
+            for (int i = 0; i < myFiles.length; i++) {
+                if (myFiles[i].isFile()) {
+                    Disk.theLogger.log(Level.SEVERE, "copy file: " +
+                                       myFiles[i]);
+
+                    theCopier.copy(myFiles[i], theDestDir);
+                }
+            }
+        } catch (IOException anIOE) {
+            theException = anIOE;
+        }
+
+        Disk.theLogger.log(Level.SEVERE, "Backup complete");
+
+        synchronized(this) {
+            isComplete = true;
+            notify();
+        }
+    }
+
+    void waitForCompletion() throws IOException {
+        synchronized(this) {
+            while (!isComplete) {
+                try {
+                    wait();
+                } catch (InterruptedException anIE) {
+                }
+            }
+        }
+
+        if (theException != null)
+            throw theException;
+    }
+}
+