summaryrefslogtreecommitdiff
path: root/tutorial/examples/serialize/ObjectIn.java
diff options
context:
space:
mode:
Diffstat (limited to 'tutorial/examples/serialize/ObjectIn.java')
-rw-r--r--tutorial/examples/serialize/ObjectIn.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/tutorial/examples/serialize/ObjectIn.java b/tutorial/examples/serialize/ObjectIn.java
new file mode 100644
index 0000000..4a3e1f1
--- /dev/null
+++ b/tutorial/examples/serialize/ObjectIn.java
@@ -0,0 +1,34 @@
+package examples.serialize;
+
+import java.io.*;
+import java.util.*;
+
+public class ObjectIn extends DataInputStream
+{
+ private Vector readObjects = new Vector();
+
+ public ObjectIn(InputStream is) {
+ super(is);
+ }
+
+ public Marshalable readObject() throws IOException {
+ int id = readInt();
+ if (id == -1) return null; /* -1 implies null */
+ if (id == -2) {
+ id = readInt();
+ return (Marshalable) readObjects.elementAt(id);
+ }
+
+ String classname = readUTF();
+ Marshalable obj;
+ try {
+ obj = (Marshalable) Class.forName(classname).newInstance();
+ } catch (Exception ex) {
+ throw new IOException(ex.toString());
+ }
+ readObjects.addElement(obj);
+ obj.readObject(this);
+
+ return obj;
+ }
+}