Repository navigation
Expand file tree
/
Copy pathBackupImp.java
More file actions
59 lines (51 loc) · 1.36 KB
/
Copy pathBackupImp.java
File metadata and controls
59 lines (51 loc) · 1.36 KB
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
package com.briup.common.imp;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Properties;
import com.briup.common.Backup;
import com.briup.common.Configuration;
import com.briup.common.ConfigurationAWare;
public class BackupImp implements Backup,ConfigurationAWare{
private String path;
@Override
public void init(Properties properties) {
path = properties.getProperty("path");
}
@Override
public void backup(String fileName, Object data) throws Exception {
File file = new File(path,fileName);
if(file.exists()){
file.delete();
}
file.createNewFile();
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
out.writeObject(data);
out.flush();
out.close();
}
@Override
public Object load(String fileName) throws Exception {
File file = new File(path,fileName);
if(!file.exists()){
return null;
}
ObjectInputStream input = new ObjectInputStream(new FileInputStream(file));
Object data = input.readObject();
input.close();
return data;
}
@Override
public void deleteBackup(String fileName) {
File file = new File(path,fileName);
if(file.exists()){
file.delete();
}
}
@Override
public void setConfiguration(Configuration configuration) {
// TODO Auto-generated method stub
}
}