1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package com.mindtree.techworks.insight.pagination;
25
26 import java.io.File;
27 import java.io.FileInputStream;
28 import java.io.FileOutputStream;
29 import java.io.IOException;
30 import java.io.ObjectInputStream;
31 import java.io.ObjectOutputStream;
32 import java.util.List;
33
34 import com.mindtree.techworks.insight.InsightConstants;
35
36
37
38
39
40
41
42
43
44
45
46 public class FilePageImpl extends PageImpl {
47
48
49
50
51 private static final long serialVersionUID = -1269915233299873471L;
52
53
54
55
56
57 public FilePageImpl(){
58 }
59
60
61
62
63
64 protected void load() {
65 try{
66 FileInputStream fil = new FileInputStream(getFile());
67 ObjectInputStream obj = new ObjectInputStream(fil);
68 List eventList = (List)obj.readObject();
69 setLogEventList(eventList);
70 obj.close();
71 fil.close();
72 } catch (IOException e) {
73 e.printStackTrace();
74 }catch (ClassNotFoundException e1) {
75 e1.printStackTrace();
76 }
77 }
78
79
80
81
82
83 protected void store() {
84 try {
85 FileOutputStream fil = new FileOutputStream(getFile());
86 ObjectOutputStream obj = new ObjectOutputStream(fil);
87 obj.writeObject(getLogEventList());
88 obj.close();
89 fil.close();
90 } catch (IOException e) {
91 e.printStackTrace();
92 }
93 }
94
95
96
97
98
99
100 private File getFile(){
101 String rootDir = System.getProperty("java.io.tmpdir") + InsightConstants.ROOT_CACHE_DIR;
102 createDir(rootDir);
103 String pageSetDir = rootDir + getPageSetNamespace();
104 createDir(pageSetDir);
105 String fileName = getPageNamespace() + InsightConstants.FILE_EXT;
106 String fullyQualFileName = pageSetDir + InsightConstants.FILE_SEPARATOR + fileName;
107 File file = new File(fullyQualFileName);
108 return file;
109 }
110
111
112
113
114
115 private void createDir(String path){
116 File dir = new File(path);
117 if(! dir.isDirectory()){
118 dir.mkdir();
119 }
120 }
121
122
123
124
125
126 protected void delete(){
127 File file = getFile();
128 if(file.exists()){
129 file.delete();
130 }
131 file = null;
132
133 }
134 }