com.threerings.io
Class ObjectInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.io.DataInputStream
              extended by com.threerings.io.ObjectInputStream
All Implemented Interfaces:
Closeable, DataInput
Direct Known Subclasses:
ClientObjectInputStream, UnreliableObjectInputStream

public class ObjectInputStream
extends DataInputStream

Used to read Streamable objects from an InputStream. Other common object types are supported as well (@see ObjectOutputStream).

See Also:
Streamable

Field Summary
protected  List<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 read from the stream.
protected  List<String> _internmap
          Maps numeric codes to pooled strings.
protected  ClassLoader _loader
          If set, an overridden class loader used to instantiate objects.
protected  Streamer _streamer
          The streamer being used currently.
protected  Map<String,String> _translations
          An optional set of class name translations to use when unserializing objects.
protected static boolean STREAM_DEBUG
          Used to activate verbose debug logging.
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
ObjectInputStream(InputStream source)
          Constructs an object input stream which will read its data from the supplied source stream.
 
Method Summary
 void addTranslation(String oldname, String newname)
          Configures this object input stream with a mapping from an old class name to a new one.
protected  com.threerings.io.ClassMapping createClassMapping(short code, String cname)
          Creates and returns a class mapping for the specified code and class name.
 void defaultReadObject()
          Reads the fields of the specified Streamable instance from the input stream using the default object streaming mechanisms (a call is not made to readObject(), even if such a method exists).
protected  com.threerings.io.ClassMapping mapClass(short code, String cname)
          Creates, adds, and returns the class mapping for the specified code and class name.
protected  void mapIntern(short code, String value)
          Adds the intern mapping for the specified code and value.
 void readBareObject(Object object)
          Reads an object from the input stream that was previously written with ObjectOutputStream.writeBareObject(Object).
protected  void readBareObject(Object object, Streamer streamer, boolean useReader)
          Reads an object from the input stream that was previously written with ObjectOutputStream.writeBareObject(Object,Streamer,boolean).
protected  com.threerings.io.ClassMapping readClassMapping()
          Reads a class mapping from the stream.
 String readIntern()
          Reads a pooled string value from the input stream.
 Object readObject()
          Reads a Streamable instance or one of the supported object types from the input stream.
 String readUnmodifiedUTF()
          Read a string encoded as real UTF-8 (rather than the modified format handled by {link #readUTF}).
 void setClassLoader(ClassLoader loader)
          Customizes the class loader used to instantiate objects read from the input stream.
 String toString()
           
 
Methods inherited from class java.io.DataInputStream
read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, readUTF, skipBytes
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_classmap

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


_internmap

protected List<String> _internmap
Maps numeric codes to pooled strings.


_current

protected Object _current
The object currently being read from the stream.


_streamer

protected Streamer _streamer
The streamer being used currently.


_loader

protected ClassLoader _loader
If set, an overridden class loader used to instantiate objects.


_translations

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


STREAM_DEBUG

protected static final boolean STREAM_DEBUG
Used to activate verbose debug logging.

See Also:
Constant Field Values
Constructor Detail

ObjectInputStream

public ObjectInputStream(InputStream source)
Constructs an object input stream which will read its data from the supplied source stream.

Method Detail

setClassLoader

public void setClassLoader(ClassLoader loader)
Customizes the class loader used to instantiate objects read from the input stream.


addTranslation

public void addTranslation(String oldname,
                           String newname)
Configures this object input stream with a mapping from an old class name to a new one. Serialized instances of the old class name will use the new class name when unserializing.


readObject

public Object readObject()
                  throws IOException,
                         ClassNotFoundException
Reads a Streamable instance or one of the supported object types from the input stream.

Throws:
IOException
ClassNotFoundException

readIntern

public String readIntern()
                  throws IOException
Reads a pooled string value from the input stream.

Throws:
IOException

mapIntern

protected void mapIntern(short code,
                         String value)
                  throws IOException
Adds the intern mapping for the specified code and value.

Throws:
IOException

readClassMapping

protected com.threerings.io.ClassMapping readClassMapping()
                                                   throws IOException,
                                                          ClassNotFoundException
Reads a class mapping from the stream.

Returns:
the class mapping, or null to represent a null value.
Throws:
IOException
ClassNotFoundException

mapClass

protected com.threerings.io.ClassMapping mapClass(short code,
                                                  String cname)
                                           throws IOException,
                                                  ClassNotFoundException
Creates, adds, and returns the class mapping for the specified code and class name.

Throws:
IOException
ClassNotFoundException

createClassMapping

protected com.threerings.io.ClassMapping createClassMapping(short code,
                                                            String cname)
                                                     throws IOException,
                                                            ClassNotFoundException
Creates and returns a class mapping for the specified code and class name.

Throws:
IOException
ClassNotFoundException

readBareObject

public void readBareObject(Object object)
                    throws IOException,
                           ClassNotFoundException
Reads an object from the input stream that was previously written with ObjectOutputStream.writeBareObject(Object).

Parameters:
object - the object to be populated from data on the stream. It cannot be null.
Throws:
IOException
ClassNotFoundException

readBareObject

protected void readBareObject(Object object,
                              Streamer streamer,
                              boolean useReader)
                       throws IOException,
                              ClassNotFoundException
Reads an object from the input stream that was previously written with ObjectOutputStream.writeBareObject(Object,Streamer,boolean).

Throws:
IOException
ClassNotFoundException

defaultReadObject

public void defaultReadObject()
                       throws IOException,
                              ClassNotFoundException
Reads the fields of the specified Streamable instance from the input stream using the default object streaming mechanisms (a call is not made to readObject(), even if such a method exists).

Throws:
IOException
ClassNotFoundException

readUnmodifiedUTF

public String readUnmodifiedUTF()
                         throws IOException
Read a string encoded as real UTF-8 (rather than the modified format handled by {link #readUTF}).

Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object