A bit of simplification.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3927 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-03-08 23:21:47 +00:00
parent 486fd770c5
commit bdfecce767
3 changed files with 14 additions and 35 deletions
@@ -151,7 +151,7 @@ public class ObjectInputStream extends DataInputStream
// create an instance of the appropriate object // create an instance of the appropriate object
Object target = cmap.streamer.createObject(this); Object target = cmap.streamer.createObject(this);
readBareObject(target, cmap.streamer); readBareObject(target, cmap.streamer, true);
return target; return target;
} catch (OutOfMemoryError oome) { } catch (OutOfMemoryError oome) {
@@ -170,20 +170,21 @@ public class ObjectInputStream extends DataInputStream
public void readBareObject (Object object) public void readBareObject (Object object)
throws IOException, ClassNotFoundException throws IOException, ClassNotFoundException
{ {
readBareObject(object, Streamer.getStreamer(object.getClass())); readBareObject(object, Streamer.getStreamer(object.getClass()), true);
} }
/** /**
* Reads an object from the input stream that was previously written * Reads an object from the input stream that was previously written
* with {@link ObjectOutputStream#writeBareObject}. * with {@link ObjectOutputStream#writeBareObject}.
*/ */
protected void readBareObject (Object object, Streamer streamer) protected void readBareObject (
Object object, Streamer streamer, boolean useReader)
throws IOException, ClassNotFoundException throws IOException, ClassNotFoundException
{ {
_current = object; _current = object;
_streamer = streamer; _streamer = streamer;
try { try {
_streamer.readObject(object, this, true); _streamer.readObject(object, this, useReader);
} finally { } finally {
// clear out our current object references // clear out our current object references
@@ -221,16 +222,6 @@ public class ObjectInputStream extends DataInputStream
", streamer=" + _streamer + "]"; ", streamer=" + _streamer + "]";
} }
/**
* Used by a {@link Streamer} that is reading an array of {@link
* Streamable} instances.
*/
protected void setCurrent (Streamer streamer, Object current)
{
_streamer = streamer;
_current = current;
}
/** Used to map classes to numeric codes and the {@link Streamer} /** Used to map classes to numeric codes and the {@link Streamer}
* instance used to write them. */ * instance used to write them. */
protected HashIntMap _classmap; protected HashIntMap _classmap;
@@ -111,7 +111,7 @@ public class ObjectOutputStream extends DataOutputStream
writeShort(cmap.code); writeShort(cmap.code);
} }
writeBareObject(object, cmap.streamer); writeBareObject(object, cmap.streamer, true);
} }
/** /**
@@ -127,19 +127,20 @@ public class ObjectOutputStream extends DataOutputStream
public void writeBareObject (Object object) public void writeBareObject (Object object)
throws IOException throws IOException
{ {
writeBareObject(object, Streamer.getStreamer(object.getClass())); writeBareObject(object, Streamer.getStreamer(object.getClass()), true);
} }
/** /**
* Write a {@link Streamable} instance without associated class metadata. * Write a {@link Streamable} instance without associated class metadata.
*/ */
protected void writeBareObject (Object obj, Streamer streamer) protected void writeBareObject (
Object obj, Streamer streamer, boolean useWriter)
throws IOException throws IOException
{ {
_current = obj; _current = obj;
_streamer = streamer; _streamer = streamer;
try { try {
_streamer.writeObject(obj, this, true); _streamer.writeObject(obj, this, useWriter);
} finally { } finally {
_current = null; _current = null;
@@ -169,16 +170,6 @@ public class ObjectOutputStream extends DataOutputStream
_streamer.writeObject(_current, this, false); _streamer.writeObject(_current, this, false);
} }
/**
* Used by a {@link Streamer} that is writing an array of {@link
* Streamable} instances.
*/
protected void setCurrent (Streamer streamer, Object current)
{
_streamer = streamer;
_current = current;
}
/** Used to map classes to numeric codes and the {@link Streamer} /** Used to map classes to numeric codes and the {@link Streamer}
* instance used to write them. */ * instance used to write them. */
protected HashMap _classmap; protected HashMap _classmap;
+4 -7
View File
@@ -182,11 +182,9 @@ public class Streamer
// now write out the populated elements // now write out the populated elements
for (int ii = 0; ii < length; ii++) { for (int ii = 0; ii < length; ii++) {
Object element = Array.get(object, ii); Object element = Array.get(object, ii);
if (element == null) { if (element != null) {
continue; out.writeBareObject(element, _delegate, useWriter);
} }
out.setCurrent(_delegate, element);
_delegate.writeObject(element, out, useWriter);
} }
} else { } else {
@@ -326,13 +324,12 @@ public class Streamer
// elements to read // elements to read
for (int ii = 0; ii < length; ii++) { for (int ii = 0; ii < length; ii++) {
if (mask.isSet(ii)) { if (mask.isSet(ii)) {
Object element = _delegate.createObject(in);
in.setCurrent(_delegate, element);
if (ObjectInputStream.STREAM_DEBUG) { if (ObjectInputStream.STREAM_DEBUG) {
Log.info(in.hashCode() + Log.info(in.hashCode() +
": Reading fixed element '" + ii + "'."); ": Reading fixed element '" + ii + "'.");
} }
_delegate.readObject(element, in, useReader); Object element = _delegate.createObject(in);
in.readBareObject(element, _delegate, useReader);
Array.set(object, ii, element); Array.set(object, ii, element);
} else if (ObjectInputStream.STREAM_DEBUG) { } else if (ObjectInputStream.STREAM_DEBUG) {
Log.info(in.hashCode() + Log.info(in.hashCode() +