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:
@@ -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,47 +81,37 @@ 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) {
|
||||||
// create a streamer instance and assign a code to this class
|
// create a streamer instance and assign a code to this class
|
||||||
Streamer streamer = Streamer.getStreamer(sclass);
|
Streamer streamer = Streamer.getStreamer(sclass);
|
||||||
// we specifically do not inline the getStreamer() call
|
// we specifically do not inline the getStreamer() call
|
||||||
// into the ClassMapping constructor because we want to be
|
// into the ClassMapping constructor because we want to be
|
||||||
// sure not to call _nextCode++ if getStreamer() throws an
|
// sure not to call _nextCode++ if getStreamer() throws an
|
||||||
// exception
|
// exception
|
||||||
cmap = new ClassMapping(_nextCode++, sclass, streamer);
|
cmap = new ClassMapping(_nextCode++, sclass, streamer);
|
||||||
_classmap.put(sclass, cmap);
|
_classmap.put(sclass, cmap);
|
||||||
|
|
||||||
// make sure we didn't blow past our maximum class count
|
// make sure we didn't blow past our maximum class count
|
||||||
if (_nextCode <= 0) {
|
if (_nextCode <= 0) {
|
||||||
throw new RuntimeException("Too many unique classes " +
|
throw new RuntimeException("Too many unique classes " +
|
||||||
"written to ObjectOutputStream");
|
"written to ObjectOutputStream");
|
||||||
}
|
|
||||||
|
|
||||||
// writing a negative class code indicates that the class
|
|
||||||
// name will follow
|
|
||||||
writeShort(-cmap.code);
|
|
||||||
writeUTF(sclass.getName());
|
|
||||||
|
|
||||||
} else {
|
|
||||||
writeShort(cmap.code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// now write the instance data
|
// writing a negative class code indicates that the class
|
||||||
_streamer = cmap.streamer;
|
// name will follow
|
||||||
_streamer.writeObject(object, this, true);
|
writeShort(-cmap.code);
|
||||||
|
writeUTF(sclass.getName());
|
||||||
|
|
||||||
} finally {
|
} else {
|
||||||
// clear out our current object references
|
writeShort(cmap.code);
|
||||||
_current = null;
|
|
||||||
_streamer = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writeBareObject(object, cmap.streamer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user