com.threerings.io
Class ObjectOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by java.io.DataOutputStream
              extended by com.threerings.io.ObjectOutputStream
All Implemented Interfaces:
Closeable, DataOutput, Flushable
Direct Known Subclasses:
UnreliableObjectOutputStream

public class ObjectOutputStream
extends DataOutputStream

Used to write Streamable objects to an OutputStream. Other common object types are supported as well: Boolean, Byte, Character, Short, Integer, Long, Float, Double, boolean[], byte[], char[], short[], int[], long[], float[], double[], Object[].

See Also:
Streamable

Field Summary
protected  Map<Class<?>,com.threerings.io.ClassMapping> _classmap
          Used to map classes to numeric codes and the Streamer instance used to write them.
protected  Object _current
          The object currently being written to the stream.
protected  Map<String,Short> _internmap
          Used to map pooled strings to numeric codes.
protected  short _nextClassCode
          A counter used to assign codes to streamed classes.
protected  short _nextInternCode
          A counter used to assign codes to pooled strings.
protected  Streamer _streamer
          The streamer being used currently.
protected  Map<String,String> _translations
          An optional set of class name translations to use when serializing objects.
 
Fields inherited from class java.io.DataOutputStream
written
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
ObjectOutputStream(OutputStream target)
          Constructs an object output stream which will write its data to the supplied target stream.
 
Method Summary
 void addTranslation(String className, String streamedName)
          Configures this object output stream with a mapping from a classname to a streamed name.
protected  com.threerings.io.ClassMapping createClassMapping(short code, Class<?> sclass, Streamer streamer)
          Creates and returns a new class mapping.
protected  Short createInternMapping(short code)
          Creates and returns a new intern mapping.
 void defaultWriteObject()
          Uses the default streamable mechanism to write the contents of the object currently being streamed.
 void writeBareObject(Object object)
          Writes a Streamable instance or one of the support object types without associated class metadata to the output stream.
protected  void writeBareObject(Object obj, Streamer streamer, boolean useWriter)
          Write a Streamable instance without associated class metadata.
protected  com.threerings.io.ClassMapping writeClassMapping(Class<?> sclass)
          Retrieves or creates the class mapping for the supplied class, writes it out to the stream, and returns a reference to it.
protected  void writeClassMapping(int code, Class<?> sclass)
          Writes out the mapping for a class.
protected  void writeExistingClassMapping(com.threerings.io.ClassMapping cmap)
          Writes an existing class mapping to the stream.
protected  void writeExistingInternMapping(short code, String value)
          Writes an existing intern mapping to the stream.
 void writeIntern(String value)
          Writes a pooled string value to the output stream.
protected  void writeInternMapping(int code, String value)
          Writes out the mapping for an intern.
protected  void writeNewClassMapping(com.threerings.io.ClassMapping cmap)
          Writes a new class mapping to the stream.
protected  void writeNewInternMapping(short code, String value)
          Writes a new intern mapping to the stream.
 void writeObject(Object object)
          Writes a Streamable instance or one of the support object types to the output stream.
 void writeUnmodifiedUTF(String str)
          Write a string encoded as real UTF-8 (rather than the modified format handled by {link #writeUTF}).
 
Methods inherited from class java.io.DataOutputStream
flush, size, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 
Methods inherited from class java.io.FilterOutputStream
close, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.io.DataOutput
write
 

Field Detail

_classmap

protected Map<Class<?>,com.threerings.io.ClassMapping> _classmap
Used to map classes to numeric codes and the Streamer instance used to write them.


_internmap

protected Map<String,Short> _internmap
Used to map pooled strings to numeric codes.


_nextClassCode

protected short _nextClassCode
A counter used to assign codes to streamed classes.


_nextInternCode

protected short _nextInternCode
A counter used to assign codes to pooled strings.


_current

protected Object _current
The object currently being written to the stream.


_streamer

protected Streamer _streamer
The streamer being used currently.


_translations

protected Map<String,String> _translations
An optional set of class name translations to use when serializing objects.

Constructor Detail

ObjectOutputStream

public ObjectOutputStream(OutputStream target)
Constructs an object output stream which will write its data to the supplied target stream.

Method Detail

addTranslation

public void addTranslation(String className,
                           String streamedName)
Configures this object output stream with a mapping from a classname to a streamed name.


writeObject

public void writeObject(Object object)
                 throws IOException
Writes a Streamable instance or one of the support object types to the output stream.

Throws:
IOException

writeIntern

public void writeIntern(String value)
                 throws IOException
Writes a pooled string value to the output stream.

Throws:
IOException

createInternMapping

protected Short createInternMapping(short code)
Creates and returns a new intern mapping.


writeNewInternMapping

protected void writeNewInternMapping(short code,
                                     String value)
                              throws IOException
Writes a new intern mapping to the stream.

Throws:
IOException

writeExistingInternMapping

protected void writeExistingInternMapping(short code,
                                          String value)
                                   throws IOException
Writes an existing intern mapping to the stream.

Throws:
IOException

writeInternMapping

protected void writeInternMapping(int code,
                                  String value)
                           throws IOException
Writes out the mapping for an intern.

Throws:
IOException

writeClassMapping

protected com.threerings.io.ClassMapping writeClassMapping(Class<?> sclass)
                                                    throws IOException
Retrieves or creates the class mapping for the supplied class, writes it out to the stream, and returns a reference to it.

Throws:
IOException

createClassMapping

protected com.threerings.io.ClassMapping createClassMapping(short code,
                                                            Class<?> sclass,
                                                            Streamer streamer)
Creates and returns a new class mapping.


writeNewClassMapping

protected void writeNewClassMapping(com.threerings.io.ClassMapping cmap)
                             throws IOException
Writes a new class mapping to the stream.

Throws:
IOException

writeExistingClassMapping

protected void writeExistingClassMapping(com.threerings.io.ClassMapping cmap)
                                  throws IOException
Writes an existing class mapping to the stream.

Throws:
IOException

writeClassMapping

protected void writeClassMapping(int code,
                                 Class<?> sclass)
                          throws IOException
Writes out the mapping for a class.

Throws:
IOException

writeBareObject

public void writeBareObject(Object object)
                     throws IOException
Writes a Streamable instance or one of the support object types without associated class metadata to the output stream. The caller is responsible for knowing the exact class of the written object, creating an instance of such and calling ObjectInputStream.readBareObject(Object) to read its data from the stream.

Parameters:
object - the object to be written. It cannot be null.
Throws:
IOException

writeBareObject

protected void writeBareObject(Object obj,
                               Streamer streamer,
                               boolean useWriter)
                        throws IOException
Write a Streamable instance without associated class metadata.

Throws:
IOException

defaultWriteObject

public void defaultWriteObject()
                        throws IOException
Uses the default streamable mechanism to write the contents of the object currently being streamed. This can only be called from within a writeObject implementation in a Streamable object.

Throws:
IOException

writeUnmodifiedUTF

public void writeUnmodifiedUTF(String str)
                        throws IOException
Write a string encoded as real UTF-8 (rather than the modified format handled by {link #writeUTF}).

Throws:
IOException