Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
SerializedFileSoup |
|
| 2.75;2.75 |
1 | /* |
|
2 | Wotonomy: OpenStep design patterns for pure Java applications. |
|
3 | Copyright (C) 2000 Michael Powers |
|
4 | ||
5 | This library is free software; you can redistribute it and/or |
|
6 | modify it under the terms of the GNU Lesser General Public |
|
7 | License as published by the Free Software Foundation; either |
|
8 | version 2.1 of the License, or (at your option) any later version. |
|
9 | ||
10 | This library is distributed in the hope that it will be useful, |
|
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 | Lesser General Public License for more details. |
|
14 | ||
15 | You should have received a copy of the GNU Lesser General Public |
|
16 | License along with this library; if not, see http://www.gnu.org |
|
17 | */ |
|
18 | ||
19 | package net.wotonomy.datastore; |
|
20 | ||
21 | import java.io.File; |
|
22 | import java.io.FileInputStream; |
|
23 | import java.io.FileNotFoundException; |
|
24 | import java.io.FileOutputStream; |
|
25 | import java.io.ObjectInputStream; |
|
26 | import java.io.ObjectOutputStream; |
|
27 | ||
28 | public class SerializedFileSoup extends FileSoup |
|
29 | { |
|
30 | public SerializedFileSoup( String aPath ) |
|
31 | { |
|
32 | 0 | super( aPath ); |
33 | 0 | } |
34 | ||
35 | // file access methods |
|
36 | ||
37 | protected boolean writeFile( String name, Object anObject ) |
|
38 | { |
|
39 | try |
|
40 | { |
|
41 | 0 | File f = new File( getHomeDirectory(), name ); |
42 | 0 | ObjectOutputStream oos = new ObjectOutputStream( |
43 | 0 | new FileOutputStream( f ) ); |
44 | 0 | oos.writeObject( anObject ); |
45 | 0 | oos.flush(); |
46 | 0 | oos.close(); |
47 | 0 | return true; |
48 | } |
|
49 | 0 | catch ( Exception exc ) |
50 | { |
|
51 | 0 | System.err.println( "SerializedFileSoup.writeFile: " + exc ); |
52 | } |
|
53 | ||
54 | 0 | return false; |
55 | } |
|
56 | ||
57 | protected Object readFile( String name ) |
|
58 | { |
|
59 | 0 | Object result = null; |
60 | ||
61 | try |
|
62 | { |
|
63 | 0 | File f = new File( getHomeDirectory(), name ); |
64 | 0 | ObjectInputStream ois = new ObjectInputStream( |
65 | 0 | new FileInputStream( f ) ); |
66 | 0 | result = ois.readObject(); |
67 | 0 | ois.close(); |
68 | } |
|
69 | 0 | catch ( FileNotFoundException exc ) |
70 | { |
|
71 | 0 | result = null; |
72 | } |
|
73 | 0 | catch ( Exception exc ) |
74 | { |
|
75 | 0 | System.err.println( "SerializedFileSoup.readFile: " + exc ); |
76 | 0 | exc.printStackTrace(); |
77 | 0 | } |
78 | 0 | return result; |
79 | } |
|
80 | ||
81 | protected boolean deleteFile( String name ) |
|
82 | { |
|
83 | try |
|
84 | { |
|
85 | 0 | File f = new File( getHomeDirectory(), name ); |
86 | 0 | if ( f.exists() ) |
87 | { |
|
88 | 0 | f.delete(); |
89 | 0 | return true; |
90 | } |
|
91 | } |
|
92 | 0 | catch ( Exception exc ) |
93 | { |
|
94 | 0 | System.err.println( "SerializedFileSoup.deleteFile: " + exc ); |
95 | 0 | } |
96 | ||
97 | 0 | return false; |
98 | } |
|
99 | ||
100 | } |
|
101 | ||
102 | /* |
|
103 | * $Log$ |
|
104 | * Revision 1.2 2006/02/19 16:26:19 cgruber |
|
105 | * Move non-unit-test code to tests project |
|
106 | * Fix up code to work with proper imports |
|
107 | * Fix maven dependencies. |
|
108 | * |
|
109 | * Revision 1.1 2006/02/16 13:18:56 cgruber |
|
110 | * Check in all sources in eclipse-friendly maven-enabled packages. |
|
111 | * |
|
112 | * Revision 1.1.1.1 2000/12/21 15:47:20 mpowers |
|
113 | * Contributing wotonomy. |
|
114 | * |
|
115 | * Revision 1.2 2000/12/20 16:25:37 michael |
|
116 | * Added log to all files. |
|
117 | * |
|
118 | * |
|
119 | */ |
|
120 |