01: package org.mandarax.zkb;
02:
03: /*
04: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: import java.io.IOException;
21: import java.io.InputStream;
22: import java.io.ObjectInputStream;
23: import java.io.ObjectOutputStream;
24: import java.io.OutputStream;
25: import java.util.Map;
26:
27: /**
28: * Object persistency service based on classical binary object serialization.
29: * Requires that all objects in the map are serializable.
30: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
31: * @version 3.4 <7 March 05>
32: * @since 2.2
33: */
34: public class BinarySerializationOPS extends AbstractOPS {
35: /**
36: * Export objects.
37: * @param out an output stream
38: * @exception an io exception
39: */
40: public synchronized void exportObjects(OutputStream out)
41: throws IOException {
42: ObjectOutputStream oout = new ObjectOutputStream(out);
43: oout.writeObject(objectsByUri);
44: }
45:
46: /**
47: * Import objects.
48: * @param in an input stream
49: * @exception an io exception
50: */
51: public synchronized void importObjects(InputStream in)
52: throws IOException {
53: ObjectInputStream oin = null;
54: try {
55: reset();
56: oin = new ObjectInputStream(in);
57: objectsByUri = (Map) oin.readObject();
58: reverseMap(objectsByUri, urisByObject);
59:
60: } catch (ClassNotFoundException x) {
61: throw new IOException(x.getMessage());
62: }
63: }
64:
65: /**
66: * Get name.
67: * @return the name of the service
68: */
69: public String getName() {
70: return "binary serialization";
71: }
72:
73: /**
74: * Get a brief description.
75: * @return a brief description of the service
76: */
77: public String getDescription() {
78: return "Object persistency service based on binary serialization, objects must be serializable";
79: }
80:
81: /**
82: * Get the extension of the associated files.
83: * @return a file extension
84: */
85: public String getExtension() {
86: return "ser";
87: }
88: }
|