1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.wotonomy.datastore;
20
21 import java.io.File;
22 import java.io.FileInputStream;
23 import java.io.FileOutputStream;
24 import java.io.IOException;
25 import java.net.MalformedURLException;
26
27 import net.wotonomy.web.xml.XMLRPCDecoder;
28 import net.wotonomy.web.xml.XMLRPCEncoder;
29
30 public class XMLFileSoup extends FileSoup
31 {
32 public XMLFileSoup( String aPath )
33 {
34 super( aPath );
35 }
36
37
38
39 protected boolean writeFile( String name, Object anObject )
40 {
41
42 try
43 {
44 File f = new File( getHomeDirectory(), name );
45 FileOutputStream fos = new FileOutputStream( f );
46 XMLRPCEncoder encoder = new XMLRPCEncoder();
47 encoder.encode( anObject, fos );
48 fos.flush();
49 fos.close();
50 }
51 catch ( Exception exc )
52 {
53 System.err.println( "XMLFileSoup.writeFile: " + exc );
54 return false;
55 }
56
57 return true;
58 }
59
60 protected Object readFile( String name )
61 {
62
63 Object result = null;
64
65 try
66 {
67 File f = new File( getHomeDirectory(), name );
68 FileInputStream fis = new FileInputStream( f );
69 XMLRPCDecoder decoder = new XMLRPCDecoder();
70 result = decoder.decode( fis, f.getAbsolutePath(), f.toURL() );
71 fis.close();
72 }
73 catch ( MalformedURLException exc )
74 {
75 result = null;
76 }
77 catch ( IOException exc )
78 {
79 result = null;
80 }
81
82 return result;
83 }
84
85 protected boolean deleteFile( String name )
86 {
87 try
88 {
89 File f = new File( getHomeDirectory(), name );
90 if ( f.exists() )
91 {
92 f.delete();
93 return true;
94 }
95 }
96 catch ( Exception exc )
97 {
98 System.err.println( "XMLFileSoup.deleteFile: " + exc );
99 }
100
101 return false;
102 }
103
104 }
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130