Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
17 naveen 1
/**
2
 * 
3
 */
4
package in.shop2020.metamodel.util;
5
 
18 naveen 6
import in.shop2020.util.Utils;
7
 
17 naveen 8
import java.io.File;
9
import java.io.FileInputStream;
10
import java.io.FileOutputStream;
11
import java.io.ObjectInputStream;
12
import java.io.ObjectOutputStream;
13
 
14
/**
15
 * @author naveen
16
 *
17
 */
18
public class DBUtils {
18 naveen 19
 
17 naveen 20
	/**
21
	 * 
22
	 * @param objectToStore
18 naveen 23
	 * @param dbFile
24
	 * @throws Exception
17 naveen 25
	 */
18 naveen 26
	public static void store(Object objectToStore, String dbFile) 
27
		throws Exception {		
21 naveen 28
		File f = new File(dbFile);
29
		if(!f.exists()) {
30
			f.createNewFile();
31
		}
32
 
33
		FileOutputStream fos = new FileOutputStream(f);
17 naveen 34
		ObjectOutputStream out = new ObjectOutputStream(fos);
35
 
36
		out.writeObject(objectToStore);
37
		out.close();
41 naveen 38
		Utils.info("Serialization complete");
17 naveen 39
	}
40
 
41
	/**
42
	 * 
18 naveen 43
	 * @param dbFile
44
	 * @return
45
	 * @throws Exception
17 naveen 46
	 */
47
	public static Object read(String dbFile) throws Exception {
21 naveen 48
		File f = new File(dbFile);
49
		if(!f.exists()) {
50
			return null;
51
		}
52
 
53
		FileInputStream fis = new FileInputStream(f);
17 naveen 54
		ObjectInputStream in = new ObjectInputStream(fis);
55
		Object obj = in.readObject();
56
		in.close();
57
 
42 naveen 58
		Utils.info("De-serialization complete");
17 naveen 59
		return obj;
60
	}
61
}