-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBackupRestore.java
93 lines (73 loc) · 3.12 KB
/
BackupRestore.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import java.io.*;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class BackupRestore {
public static void BackupFile(String filepath, JFrame parent) {
// Enter Backup Folder path in DestinationFilePath
String destfilepath = "/home/aryan/Desktop/sem5/Microproject/AJP/Source Code/Backup/"
+ filepath.substring(filepath.lastIndexOf("/") + 1, filepath.length());
long st_time = new Date().getTime();
try {
BufferedInputStream fis = new BufferedInputStream(new FileInputStream(filepath));
BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream(destfilepath));
int total = fis.available();
ProgressDialog jp = new ProgressDialog(parent);
jp.jprog.setMinimum(0);
jp.jprog.setMaximum(total);
jp.setTitle("File Backup in Progress...");
jp.jprog.setStringPainted(true);
jp.setVisible(true);
int j = 1;
int b = fis.read();
while (b != -1) {
fout.write((byte) b);
b = fis.read();
// progressbar
jp.jprog.paintImmediately(0, 0, 1000, 100);
jp.jprog.setValue(j);
j++;
}
jp.setVisible(false);
fis.close();
fout.close();
} catch (Exception e) {
e.printStackTrace();
}
long end_time = new Date().getTime();
JOptionPane.showMessageDialog(null, "File BackUp Successful \n Time Taken: " + (end_time - st_time) / 1000,
"Message Box", JOptionPane.INFORMATION_MESSAGE);
}
public static void RestoreFile(String filepath, String folder, JFrame parent) {
String destfilepath = folder + filepath.substring(filepath.lastIndexOf("/") , filepath.length());
long st_time = new Date().getTime();
try {
BufferedInputStream fis = new BufferedInputStream(new FileInputStream(filepath));
BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream(destfilepath));
int total = fis.available();
ProgressDialog jp = new ProgressDialog(parent);
jp.jprog.setMinimum(0);
jp.jprog.setMaximum(total);
jp.setTitle("File Restore in Progress...");
jp.jprog.setStringPainted(true);
jp.setVisible(true);
int j = 1;
int b = fis.read();
while (b != -1) {
fout.write((byte) b);
b = fis.read();
// progressbar
jp.jprog.paintImmediately(0, 0, 1000, 100);
jp.jprog.setValue(j);
j++;
}
fis.close();
fout.close();
jp.setVisible(false);
} catch (Exception e) {
e.printStackTrace();
}
long end_time = new Date().getTime();
JOptionPane.showMessageDialog(null, "File Restore Successful \n Time Taken: " + (end_time - st_time) / 1000+" sec","Message Box", JOptionPane.INFORMATION_MESSAGE);
}
}