Use the ArrayStreamer to stream regular Arrays as well.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4113 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -19,7 +19,6 @@ public class ArrayStreamer extends Streamer
|
||||
super(TypedArray, jname);
|
||||
|
||||
var secondChar :String = jname.charAt(1);
|
||||
|
||||
if (secondChar === "[") {
|
||||
// if we're a multi-dimensional array then we need a delegate
|
||||
_delegate = Streamer.getStreamerByJavaName(jname.substring(1));
|
||||
@@ -44,8 +43,27 @@ public class ArrayStreamer extends Streamer
|
||||
|
||||
public override function isStreamerFor (obj :Object) :Boolean
|
||||
{
|
||||
return (obj is TypedArray) &&
|
||||
((obj as TypedArray).getJavaType() === _jname);
|
||||
if (_jname === "[Ljava.lang.Object;") {
|
||||
// we fall back to streaming any array as Object
|
||||
return (obj is Array);
|
||||
|
||||
} else {
|
||||
return (obj is TypedArray) &&
|
||||
((obj as TypedArray).getJavaType() === _jname);
|
||||
}
|
||||
}
|
||||
|
||||
public override function isStreamerForClass (clazz :Class) :Boolean
|
||||
{
|
||||
if (_jname === "[Ljava.lang.Object;") {
|
||||
return (clazz != TypedArray) &&
|
||||
ClassUtil.isAssignableAs(Array, clazz);
|
||||
|
||||
} else {
|
||||
return false; // TODO: we're kinda fucked for finding a streamer
|
||||
// by class for TypedArrays here. The caller should be passing
|
||||
// the java name.
|
||||
}
|
||||
}
|
||||
|
||||
public override function createObject (ins :ObjectInputStream) :Object
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.threerings.io.streamers {
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamer;
|
||||
import com.threerings.io.TypedArray;
|
||||
|
||||
/**
|
||||
* A Streamer for Array objects.
|
||||
*/
|
||||
public class ObjectArrayStreamer extends Streamer
|
||||
{
|
||||
public function ObjectArrayStreamer ()
|
||||
{
|
||||
super(Array, "[Ljava.lang.Object;");
|
||||
}
|
||||
|
||||
public override function isStreamerFor (obj :Object) :Boolean
|
||||
{
|
||||
// don't let TypedArrays be streamed with this streamer
|
||||
return !(obj is TypedArray) && super.isStreamerFor(obj);
|
||||
}
|
||||
|
||||
public override function createObject (ins :ObjectInputStream) :Object
|
||||
{
|
||||
return new Array(ins.readInt());
|
||||
}
|
||||
|
||||
public override function writeObject (obj :Object, out :ObjectOutputStream)
|
||||
:void
|
||||
{
|
||||
var arr :Array = (obj as Array);
|
||||
out.writeInt(arr.length);
|
||||
for (var ii :int = 0; ii < arr.length; ii++) {
|
||||
out.writeObject(arr[ii]);
|
||||
}
|
||||
}
|
||||
|
||||
public override function readObject (obj :Object, ins :ObjectInputStream)
|
||||
:void
|
||||
{
|
||||
var arr :Array = (obj as Array);
|
||||
for (var ii :int = 0; ii < arr.length; ii++) {
|
||||
arr[ii] = ins.readObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user