Har! More progress mateys.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: DObject.java,v 1.2 2001/05/23 04:03:40 mdb Exp $
|
||||
// $Id: DObject.java,v 1.3 2001/05/29 03:27:59 mdb Exp $
|
||||
|
||||
package com.samskivert.cocktail.cher.dobj;
|
||||
|
||||
@@ -7,25 +7,17 @@ import java.io.IOException;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
import com.samskivert.cocktail.cher.io.TypedObject;
|
||||
import com.samskivert.cocktail.cher.io.TypedObjectFactory;
|
||||
|
||||
public class DObject implements TypedObject
|
||||
public class DObject
|
||||
{
|
||||
public static short TYPE = 400;
|
||||
|
||||
public short getType ()
|
||||
{
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
public void writeTo (DataOutputStream out)
|
||||
throws IOException
|
||||
{
|
||||
// nothing doing!
|
||||
}
|
||||
|
||||
public void readFrom (DataInputStream in)
|
||||
throws IOException
|
||||
{
|
||||
// nothing doing!
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// $Id: DObjectFactory.java,v 1.1 2001/05/29 03:27:59 mdb Exp $
|
||||
|
||||
package com.samskivert.cocktail.cher.dobj;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
import com.samskivert.cocktail.cher.io.ObjectStreamException;
|
||||
|
||||
/**
|
||||
* The distributed object factory is responsible for marshalling and
|
||||
* unmarshalling distributed objects to and from streams so that they can
|
||||
* be communicated between the client and server.
|
||||
*/
|
||||
public class DObjectFactory
|
||||
{
|
||||
public static void writeTo (DataOutputStream out, DObject dobj)
|
||||
throws IOException
|
||||
{
|
||||
// first we write the class of the object to the stream
|
||||
out.writeUTF(dobj.getClass().getName());
|
||||
// then we write the object itself
|
||||
dobj.writeTo(out);
|
||||
}
|
||||
|
||||
public static DObject readFrom (DataInputStream in)
|
||||
throws IOException
|
||||
{
|
||||
try {
|
||||
Class clazz = Class.forName(in.readUTF());
|
||||
DObject dobj = (DObject)clazz.newInstance();
|
||||
dobj.readFrom(in);
|
||||
return dobj;
|
||||
|
||||
} catch (Exception e) {
|
||||
String errmsg = "Unable to unserialize dobj: " + e;
|
||||
throw new ObjectStreamException(errmsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user