Old man Occam came a knockin'.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3857 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-02-15 04:05:40 +00:00
parent 174fa1b9c6
commit 892bdce01d
2 changed files with 52 additions and 61 deletions
@@ -150,24 +150,13 @@ public class ObjectInputStream extends DataInputStream
} }
// create an instance of the appropriate object // create an instance of the appropriate object
_streamer = cmap.streamer; Object target = cmap.streamer.createObject(this);
Object target = _streamer.createObject(this); readBareObject(target, cmap.streamer);
_current = target;
// now read the instance data
_streamer.readObject(target, this, true);
// and return the newly read object
return target; return target;
} catch (OutOfMemoryError oome) { } catch (OutOfMemoryError oome) {
throw (IOException) throw (IOException)
new IOException("Malformed object data").initCause(oome); new IOException("Malformed object data").initCause(oome);
} finally {
// clear out our current object references
_current = null;
_streamer = null;
} }
} }
@@ -181,12 +170,19 @@ public class ObjectInputStream extends DataInputStream
public void readBareObject (Object object) public void readBareObject (Object object)
throws IOException, ClassNotFoundException throws IOException, ClassNotFoundException
{ {
try { readBareObject(object, Streamer.getStreamer(object.getClass()));
// obtain the streamer for objects of this class }
_streamer = Streamer.getStreamer(object.getClass());
_current = object;
// now read the instance data /**
* Reads an object from the input stream that was previously written
* with {@link ObjectOutputStream#writeBareObject}.
*/
protected void readBareObject (Object object, Streamer streamer)
throws IOException, ClassNotFoundException
{
_current = object;
_streamer = streamer;
try {
_streamer.readObject(object, this, true); _streamer.readObject(object, this, true);
} finally { } finally {
@@ -1,5 +1,5 @@
// //
// $Id: ObjectOutputStream.java,v 1.3 2004/08/27 02:12:36 mdb Exp $ // $Id$
// //
// Narya library - tools for developing networked games // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -81,11 +81,9 @@ public class ObjectOutputStream extends DataOutputStream
_classmap = new HashMap(); _classmap = new HashMap();
} }
try {
// otherwise, look up the class mapping record // otherwise, look up the class mapping record
Class sclass = object.getClass(); Class sclass = object.getClass();
ClassMapping cmap = (ClassMapping)_classmap.get(sclass); ClassMapping cmap = (ClassMapping)_classmap.get(sclass);
_current = object;
// create a class mapping for this class if we've not got one // create a class mapping for this class if we've not got one
if (cmap == null) { if (cmap == null) {
@@ -113,15 +111,7 @@ public class ObjectOutputStream extends DataOutputStream
writeShort(cmap.code); writeShort(cmap.code);
} }
// now write the instance data writeBareObject(object, cmap.streamer);
_streamer = cmap.streamer;
_streamer.writeObject(object, this, true);
} finally {
// clear out our current object references
_current = null;
_streamer = null;
}
} }
/** /**
@@ -137,16 +127,21 @@ public class ObjectOutputStream extends DataOutputStream
public void writeBareObject (Object object) public void writeBareObject (Object object)
throws IOException throws IOException
{ {
try { writeBareObject(object, Streamer.getStreamer(object.getClass()));
// get the streamer for objects of this type }
_streamer = Streamer.getStreamer(object.getClass());
_current = object;
// now write the instance data /**
_streamer.writeObject(object, this, true); * Write a {@link Streamable} instance without associated class metadata.
*/
protected void writeBareObject (Object obj, Streamer streamer)
throws IOException
{
_current = obj;
_streamer = streamer;
try {
_streamer.writeObject(obj, this, true);
} finally { } finally {
// clear out our current object references
_current = null; _current = null;
_streamer = null; _streamer = null;
} }