From baa45c51c13a598411f1c0d1ea9f9bacfeeb76b6 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Wed, 15 Mar 2006 02:29:10 +0000 Subject: [PATCH] Added class translation support so that I could write a DSet converter. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3947 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/io/ObjectOutputStream.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/java/com/threerings/io/ObjectOutputStream.java b/src/java/com/threerings/io/ObjectOutputStream.java index 957ac6bc0..f538f84c3 100644 --- a/src/java/com/threerings/io/ObjectOutputStream.java +++ b/src/java/com/threerings/io/ObjectOutputStream.java @@ -63,6 +63,18 @@ public class ObjectOutputStream extends DataOutputStream super(target); } + /** + * Configures this object output stream with a mapping from a classname + * to a streamed name. + */ + public void addTranslation (String className, String streamedName) + { + if (_translations == null) { + _translations = new HashMap(); + } + _translations.put(className, streamedName); + } + /** * Writes a {@link Streamable} instance or one of the support object * types to the output stream. @@ -105,7 +117,14 @@ public class ObjectOutputStream extends DataOutputStream // writing a negative class code indicates that the class // name will follow writeShort(-cmap.code); - writeUTF(sclass.getName()); + String cname = sclass.getName(); + if (_translations != null) { + String tname = (String) _translations.get(cname); + if (tname != null) { + cname = tname; + } + } + writeUTF(cname); } else { writeShort(cmap.code); @@ -182,4 +201,8 @@ public class ObjectOutputStream extends DataOutputStream /** The streamer being used currently. */ protected Streamer _streamer; + + /** An optional set of class name translations to use when serializing + * objects. */ + protected HashMap _translations; }