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:
@@ -236,6 +236,6 @@ public class ObjectInputStream
|
||||
|
||||
|
||||
|
||||
static var _tempy :int = 0;
|
||||
private static var _tempy :int = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class Streamer
|
||||
}
|
||||
|
||||
for each (var streamer :Streamer in _streamers) {
|
||||
if (streamer._target == clazz) {
|
||||
if (streamer.isStreamerForClass(clazz)) {
|
||||
return streamer;
|
||||
}
|
||||
}
|
||||
@@ -106,6 +106,11 @@ public class Streamer
|
||||
return (obj is _target); // scripting langs are weird
|
||||
}
|
||||
|
||||
public function isStreamerForClass (clazz :Class) :Boolean
|
||||
{
|
||||
return (clazz == _target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the String to use to identify the class that we're streaming.
|
||||
*/
|
||||
@@ -143,8 +148,8 @@ public class Streamer
|
||||
if (_streamers == null) {
|
||||
_streamers = [
|
||||
new StringStreamer(),
|
||||
new ArrayStreamer("[Ljava.lang.Object;"),
|
||||
new NumberStreamer(),
|
||||
new ObjectArrayStreamer(),
|
||||
new ByteArrayStreamer(),
|
||||
new ByteStreamer(),
|
||||
new ShortStreamer(),
|
||||
|
||||
@@ -32,5 +32,8 @@ public class Translations
|
||||
|
||||
/** A mapping of java names to actionscript names. */
|
||||
protected static var _fromServer :SimpleMap = new SimpleMap();
|
||||
|
||||
// initialize some standard classes
|
||||
addTranslation("Object", "java.lang.Object");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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