comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:3dc0c5604566
1 package org.dancres.blitz.disk;
2
3 import java.io.IOException;
4 import java.io.File;
5
6 import java.util.logging.Level;
7
8 import org.dancres.io.FileCopier;
9
10 class BackupTask implements Runnable {
11 private File theSourceDir;
12 private File theDestDir;
13
14 private FileCopier theCopier = new FileCopier();
15
16 private boolean isComplete = false;
17 private IOException theException = null;
18
19 BackupTask(File aSource, File aDest) {
20 theSourceDir = aSource;
21 theDestDir = aDest;
22 }
23
24 public void run() {
25 Disk.theLogger.log(Level.SEVERE, "Start backup: " + theSourceDir
26 + ", " + theDestDir);
27
28 File[] myFiles = theSourceDir.listFiles();
29
30 Disk.theLogger.log(Level.SEVERE, "Number of files: " +
31 myFiles.length);
32
33 try {
34 for (int i = 0; i < myFiles.length; i++) {
35 if (myFiles[i].isFile()) {
36 Disk.theLogger.log(Level.SEVERE, "copy file: " +
37 myFiles[i]);
38
39 theCopier.copy(myFiles[i], theDestDir);
40 }
41 }
42 } catch (IOException anIOE) {
43 theException = anIOE;
44 }
45
46 Disk.theLogger.log(Level.SEVERE, "Backup complete");
47
48 synchronized(this) {
49 isComplete = true;
50 notify();
51 }
52 }
53
54 void waitForCompletion() throws IOException {
55 synchronized(this) {
56 while (!isComplete) {
57 try {
58 wait();
59 } catch (InterruptedException anIE) {
60 }
61 }
62 }
63
64 if (theException != null)
65 throw theException;
66 }
67 }
68