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
This commit is contained in:
@@ -63,6 +63,18 @@ public class ObjectOutputStream extends DataOutputStream
|
|||||||
super(target);
|
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
|
* Writes a {@link Streamable} instance or one of the support object
|
||||||
* types to the output stream.
|
* types to the output stream.
|
||||||
@@ -105,7 +117,14 @@ public class ObjectOutputStream extends DataOutputStream
|
|||||||
// writing a negative class code indicates that the class
|
// writing a negative class code indicates that the class
|
||||||
// name will follow
|
// name will follow
|
||||||
writeShort(-cmap.code);
|
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 {
|
} else {
|
||||||
writeShort(cmap.code);
|
writeShort(cmap.code);
|
||||||
@@ -182,4 +201,8 @@ public class ObjectOutputStream extends DataOutputStream
|
|||||||
|
|
||||||
/** The streamer being used currently. */
|
/** The streamer being used currently. */
|
||||||
protected Streamer _streamer;
|
protected Streamer _streamer;
|
||||||
|
|
||||||
|
/** An optional set of class name translations to use when serializing
|
||||||
|
* objects. */
|
||||||
|
protected HashMap _translations;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user