Source code: feynman/framework/datastore/FileDataStore.java
1 /*
2 * $Header: /cvsroot/feynman/src/feynman/framework/datastore/FileDataStore.java,v 1.1.1.1 2002/11/12 02:25:41 wesley_bailey Exp $
3 * $Revision: 1.1.1.1 $
4 * $Date: 2002/11/12 02:25:41 $
5 * $Copyright: Copyright (C) 2002 Path Integral Software $
6 */
7 package feynman.framework.datastore;
8
9 import java.io.File;
10 import java.io.FileWriter;
11 import java.io.PrintWriter;
12 import feynman.framework.system.PhysicalMeasurement;
13
14 /**
15 * File based implementation of the <b>DataStore</b> interface. This
16 * class makes use of the <em>toString()</em> method defined in the
17 * <b>PhysicalMeasurement</b> interface.
18 *
19 * @author Wes Bailey
20 * @version $Revision: 1.1.1.1 $ $Date: 2002/11/12 02:25:41 $
21 */
22 public class FileDataStore implements DataStore {
23
24 // Define the instance variables.
25 private File file;
26 private FileWriter fw;
27 private PrintWriter pw;
28
29 FileDataStore() {
30 // Factory only instantiation.
31 }
32
33 /**
34 * Method to open a file for writing <b>PhysicalMeasurement</b> data to.
35 */
36 public void open(String source) throws ConnectionException {
37
38 // Create the file and open the writers.
39 try {
40 file = new File(source);
41 fw = new FileWriter(file);
42 pw = new PrintWriter(fw);
43 }
44 catch (Exception e) {
45 throw new ConnectionException(e.toString());
46 }
47
48 }
49
50 /**
51 * Method to write the <b>PhysicalMeasurement</b> data to the file.
52 */
53 public void save(PhysicalMeasurement pm) {
54
55 pw.println(pm.toString());
56
57 }
58
59 /**
60 * Method to close the <b>PhysicalMeasurement</b> data file for writing.
61 */
62 public void close() throws ConnectionException {
63
64 // Be a good citizen and close the streams.
65 try {
66 pw.close();
67 fw.close();
68 }
69 catch (Exception e) {
70 throw new ConnectionException(e.toString());
71 }
72
73 }
74
75 }