com.threerings.export
Class BinaryImporter

java.lang.Object
  extended by com.threerings.export.Importer
      extended by com.threerings.export.BinaryImporter
All Implemented Interfaces:
Closeable

public class BinaryImporter
extends Importer

Imports from the compact binary format generated by BinaryExporter.


Nested Class Summary
protected  class BinaryImporter.ClassData
          Contains information on an exportable class.
protected  class BinaryImporter.ClassWrapper
          Contains information on a class in the stream, which may or may not be resolvable.
protected  class BinaryImporter.IDReader
          Reads in integer identifiers using a width that depends on the highest value read so far.
 
Field Summary
protected  InputStream _base
          The underlying input stream.
protected  HashMap<BinaryImporter.ClassWrapper,BinaryImporter.ClassData> _classData
          Class
protected  HashIntMap<BinaryImporter.ClassWrapper> _classes
          Maps ids to classes read.
protected  BinaryImporter.IDReader _classIdReader
          Used to read class ids.
protected  HashMap<String,Object> _fields
          Field values associated with the current object.
protected  DataInputStream _in
          The stream that we use for reading data.
protected  BinaryImporter.ClassWrapper _objectClass
          The wrapper for the object class.
protected  BinaryImporter.IDReader _objectIdReader
          Used to read object ids.
protected  HashIntMap<Object> _objects
          Maps ids to objects read.
protected  BinaryImporter.ClassWrapper _stringClass
          The wrapper for the String class.
protected  HashMap<Class<?>,BinaryImporter.ClassWrapper> _wrappersByClass
          Maps class objects to wrapper objects (for classes identified by reference).
protected  HashMap<String,BinaryImporter.ClassWrapper> _wrappersByName
          Maps class names to wrapper objects (for classes identified in the stream).
protected static Object NULL
          Signifies a null entry in the object map.
 
Fields inherited from class com.threerings.export.Importer
_marshaller, _object
 
Constructor Summary
BinaryImporter(InputStream in)
          Creates an importer to read from the specified stream.
 
Method Summary
 void close()
          Closes the underlying stream.
protected  BinaryImporter.ClassWrapper getClassWrapper(Class<?> clazz)
          Returns a shared class wrapper instance.
protected  BinaryImporter.ClassWrapper getClassWrapper(String name, byte flags)
          Returns a shared class wrapper instance.
protected  Object read(BinaryImporter.ClassWrapper clazz)
          Reads in an object of the specified class.
protected  Object read(Class<?> clazz)
          Reads in an object of the specified class.
 boolean read(String name, boolean defvalue)
          Reads a boolean value associated with the current object.
 byte read(String name, byte defvalue)
          Reads a byte value associated with the current object.
 char read(String name, char defvalue)
          Reads a character value associated with the current object.
 double read(String name, double defvalue)
          Reads a double value associated with the current object.
 float read(String name, float defvalue)
          Reads a float value associated with the current object.
 int read(String name, int defvalue)
          Reads an integer value associated with the current object.
 long read(String name, long defvalue)
          Reads a long value associated with the current object.
 short read(String name, short defvalue)
          Reads a short value associated with the current object.
<T> T
read(String name, T defvalue, Class<T> clazz)
          Reads an object value associated with the current object.
protected  BinaryImporter.ClassWrapper readClass()
          Reads in a class reference.
protected  Collection<Object> readEntries(Collection<Object> collection)
          Populates the supplied collection with the entries under the current element.
protected  Map<Object,Object> readEntries(Map<Object,Object> map)
          Populates the supplied map with the entries under the current element.
protected  void readEntries(Object[] array, BinaryImporter.ClassWrapper cclazz)
          Populates the supplied array with the entries under the current element.
 Object readObject()
          Imports an object from the underlying stream.
protected  Object readValue(BinaryImporter.ClassWrapper clazz, int objectId)
          Reads in an object of the specified class.
 
Methods inherited from class com.threerings.export.Importer
defaultReadFields, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, readFields
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_base

protected InputStream _base
The underlying input stream.


_in

protected DataInputStream _in
The stream that we use for reading data.


_objects

protected HashIntMap<Object> _objects
Maps ids to objects read. A null value indicates that the stream has not yet been initialized.


_objectIdReader

protected BinaryImporter.IDReader _objectIdReader
Used to read object ids.


_fields

protected HashMap<String,Object> _fields
Field values associated with the current object.


_wrappersByName

protected HashMap<String,BinaryImporter.ClassWrapper> _wrappersByName
Maps class names to wrapper objects (for classes identified in the stream).


_wrappersByClass

protected HashMap<Class<?>,BinaryImporter.ClassWrapper> _wrappersByClass
Maps class objects to wrapper objects (for classes identified by reference).


_objectClass

protected BinaryImporter.ClassWrapper _objectClass
The wrapper for the object class.


_stringClass

protected BinaryImporter.ClassWrapper _stringClass
The wrapper for the String class.


_classes

protected HashIntMap<BinaryImporter.ClassWrapper> _classes
Maps ids to classes read.


_classIdReader

protected BinaryImporter.IDReader _classIdReader
Used to read class ids.


_classData

protected HashMap<BinaryImporter.ClassWrapper,BinaryImporter.ClassData> _classData
Class data.


NULL

protected static final Object NULL
Signifies a null entry in the object map.

Constructor Detail

BinaryImporter

public BinaryImporter(InputStream in)
Creates an importer to read from the specified stream.

Method Detail

readObject

public Object readObject()
                  throws IOException
Description copied from class: Importer
Imports an object from the underlying stream.

Specified by:
readObject in class Importer
Throws:
IOException

read

public boolean read(String name,
                    boolean defvalue)
             throws IOException
Description copied from class: Importer
Reads a boolean value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

read

public byte read(String name,
                 byte defvalue)
          throws IOException
Description copied from class: Importer
Reads a byte value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

read

public char read(String name,
                 char defvalue)
          throws IOException
Description copied from class: Importer
Reads a character value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

read

public double read(String name,
                   double defvalue)
            throws IOException
Description copied from class: Importer
Reads a double value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

read

public float read(String name,
                  float defvalue)
           throws IOException
Description copied from class: Importer
Reads a float value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

read

public int read(String name,
                int defvalue)
         throws IOException
Description copied from class: Importer
Reads an integer value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

read

public long read(String name,
                 long defvalue)
          throws IOException
Description copied from class: Importer
Reads a long value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

read

public short read(String name,
                  short defvalue)
           throws IOException
Description copied from class: Importer
Reads a short value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

read

public <T> T read(String name,
                  T defvalue,
                  Class<T> clazz)
       throws IOException
Description copied from class: Importer
Reads an object value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

close

public void close()
           throws IOException
Description copied from class: Importer
Closes the underlying stream.

Specified by:
close in interface Closeable
Specified by:
close in class Importer
Throws:
IOException

read

protected Object read(Class<?> clazz)
               throws IOException
Reads in an object of the specified class.

Throws:
IOException

read

protected Object read(BinaryImporter.ClassWrapper clazz)
               throws IOException
Reads in an object of the specified class.

Throws:
IOException

readValue

protected Object readValue(BinaryImporter.ClassWrapper clazz,
                           int objectId)
                    throws IOException
Reads in an object of the specified class.

Throws:
IOException

readClass

protected BinaryImporter.ClassWrapper readClass()
                                         throws IOException
Reads in a class reference. While it's possibly simply to write the class reference out as a normal object, we keep a separate id space for object/field classes in order to keep the ids small.

Throws:
IOException

readEntries

protected void readEntries(Object[] array,
                           BinaryImporter.ClassWrapper cclazz)
                    throws IOException
Populates the supplied array with the entries under the current element.

Throws:
IOException

readEntries

protected Collection<Object> readEntries(Collection<Object> collection)
                                  throws IOException
Populates the supplied collection with the entries under the current element.

Returns:
a reference to the collection passed, for chaining.
Throws:
IOException

readEntries

protected Map<Object,Object> readEntries(Map<Object,Object> map)
                                  throws IOException
Populates the supplied map with the entries under the current element.

Returns:
a reference to the map passed, for chaining.
Throws:
IOException

getClassWrapper

protected BinaryImporter.ClassWrapper getClassWrapper(String name,
                                                      byte flags)
Returns a shared class wrapper instance.


getClassWrapper

protected BinaryImporter.ClassWrapper getClassWrapper(Class<?> clazz)
Returns a shared class wrapper instance.