JSX
Class ObjectReader

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--java.io.ObjectInputStream
              |
              +--JSX.ObjectReader
All Implemented Interfaces:
DataInput, ObjectInput, ObjectStreamConstants

public class ObjectReader
extends ObjectInputStream

ObjectReader can be used in place of ObjectInputStream, to serialize object graphs to XML, instead of the binary format. It implements all the core features of ObjectInputStream - refer to Sun's javadocs and tutorials for more information. ObjectReader does not require classes to implement java.io.Serialization, nor is serialVersionUID needed for class evolution.

See Also:
Object Serialization Specification, Section 3, Object Input Classes

Nested Class Summary
 class ObjectReader.GetFieldImpl
           
 
Field Summary
 
Fields inherited from interface java.io.ObjectStreamConstants
baseWireHandle, PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, SC_BLOCK_DATA, SC_EXTERNALIZABLE, SC_SERIALIZABLE, SC_WRITE_METHOD, STREAM_MAGIC, STREAM_VERSION, SUBCLASS_IMPLEMENTATION_PERMISSION, SUBSTITUTION_PERMISSION, TC_ARRAY, TC_BASE, TC_BLOCKDATA, TC_BLOCKDATALONG, TC_CLASS, TC_CLASSDESC, TC_ENDBLOCKDATA, TC_EXCEPTION, TC_LONGSTRING, TC_MAX, TC_NULL, TC_OBJECT, TC_PROXYCLASSDESC, TC_REFERENCE, TC_RESET, TC_STRING
 
Constructor Summary
ObjectReader(JSX.DataReaderI dataReader)
           
ObjectReader(JSX.DataReaderI dataReader, ClassLoader cl)
          Pass in a classloader for JSX to lookup classes that are being deserialized.
ObjectReader(InputStream in)
           
ObjectReader(InputStream in, ClassLoader cl)
          Pass in a classloader for JSX to lookup classes that are being deserialized.
ObjectReader(Reader reader)
           
ObjectReader(Reader reader, ClassLoader cl)
          Pass in a classloader for JSX to lookup classes that are being deserialized.
 
Method Summary
 String _readUTF()
           
 int available()
          returns 1 if source is ready; else 0
 void close()
           
 void defaultReadObject()
          Call from within a class's readObject(ObjectInputStream ois) method, so the object is deserialized by the default way.
 void disableExternalization()
          Create object and step through inherited classes +
protected  boolean enableResolveObject(boolean enable)
           
 HashMap getHash()
           
static void main(String[] args)
          USAGE: java JSX.ObjectReader fileName (use "-" for stdin, defaults to example.xml)
 int read()
           
 int read(byte[] buf, int off, int len)
           
 boolean readBoolean()
           
 byte readByte()
           
 char readChar()
           
protected  ObjectStreamClass readClassDescriptor()
          Never called by JSX, so overriding it has no effect.
 double readDouble()
           
 ObjectInputStream.GetField readFields()
          Reads the stream, same as defaultReadObject, but instead of storing into fields, it stores it in a hash that can be queried.
 float readFloat()
           
 void readFully(byte[] buf)
           
 void readFully(byte[] buf, int off, int len)
           
 int readInt()
           
 String readLine()
          This operates at the wrong level for reading object encoded as XML - this method calls _readUTF() instead, and so will work if characters have been written explicitly as object data
 long readLong()
           
protected  Object readObjectOverride()
           
 short readShort()
           
protected  void readStreamHeader()
          Not implemented
 Object readUnshared()
           
 int readUnsignedByte()
           
 int readUnsignedShort()
           
 String readUTF()
           
 void registerValidation(ObjectInputValidation obj, int prio)
           
protected  Class resolveClass(ObjectStreamClass osc, String sergeyName)
          First attempts to load classes with Thread.currentThread().getContextClassLoader(); if fails, it defaults to the classloader that loaded JSX.Reader.
protected  Object resolveObject(Object obj)
          Override this method, to replace a deserialized object with another
 
Methods inherited from class java.io.ObjectInputStream
readObject, resolveClass, resolveProxyClass, skipBytes
 
Methods inherited from class java.io.InputStream
mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.io.ObjectInput
read, skip
 

Constructor Detail

ObjectReader

public ObjectReader(InputStream in)
             throws IOException

ObjectReader

public ObjectReader(InputStream in,
                    ClassLoader cl)
             throws IOException
Pass in a classloader for JSX to lookup classes that are being deserialized.


ObjectReader

public ObjectReader(Reader reader)
             throws IOException

ObjectReader

public ObjectReader(Reader reader,
                    ClassLoader cl)
             throws IOException
Pass in a classloader for JSX to lookup classes that are being deserialized.


ObjectReader

public ObjectReader(JSX.DataReaderI dataReader)
             throws IOException

ObjectReader

public ObjectReader(JSX.DataReaderI dataReader,
                    ClassLoader cl)
             throws IOException
Pass in a classloader for JSX to lookup classes that are being deserialized.

Method Detail

main

public static void main(String[] args)
                 throws IOException,
                        ClassNotFoundException
USAGE: java JSX.ObjectReader fileName (use "-" for stdin, defaults to example.xml)

IOException
ClassNotFoundException

getHash

public HashMap getHash()

close

public void close()
           throws IOException
Specified by:
close in interface ObjectInput
Overrides:
close in class ObjectInputStream
IOException

available

public int available()
              throws IOException
returns 1 if source is ready; else 0

Specified by:
available in interface ObjectInput
Overrides:
available in class ObjectInputStream
IOException

registerValidation

public void registerValidation(ObjectInputValidation obj,
                               int prio)
                        throws NotActiveException,
                               InvalidObjectException
Overrides:
registerValidation in class ObjectInputStream
NotActiveException
InvalidObjectException

readBoolean

public boolean readBoolean()
                    throws IOException
Specified by:
readBoolean in interface DataInput
Overrides:
readBoolean in class ObjectInputStream
IOException

readByte

public byte readByte()
              throws IOException
Specified by:
readByte in interface DataInput
Overrides:
readByte in class ObjectInputStream
IOException

readChar

public char readChar()
              throws IOException
Specified by:
readChar in interface DataInput
Overrides:
readChar in class ObjectInputStream
IOException

readUnsignedByte

public int readUnsignedByte()
                     throws IOException
Specified by:
readUnsignedByte in interface DataInput
Overrides:
readUnsignedByte in class ObjectInputStream
IOException

readShort

public short readShort()
                throws IOException
Specified by:
readShort in interface DataInput
Overrides:
readShort in class ObjectInputStream
IOException

readUnsignedShort

public int readUnsignedShort()
                      throws IOException
Specified by:
readUnsignedShort in interface DataInput
Overrides:
readUnsignedShort in class ObjectInputStream
IOException

readInt

public int readInt()
            throws IOException
Specified by:
readInt in interface DataInput
Overrides:
readInt in class ObjectInputStream
IOException

readLong

public long readLong()
              throws IOException
Specified by:
readLong in interface DataInput
Overrides:
readLong in class ObjectInputStream
IOException

readFloat

public float readFloat()
                throws IOException
Specified by:
readFloat in interface DataInput
Overrides:
readFloat in class ObjectInputStream
IOException

readDouble

public double readDouble()
                  throws IOException
Specified by:
readDouble in interface DataInput
Overrides:
readDouble in class ObjectInputStream
IOException

readLine

public String readLine()
                throws IOException
This operates at the wrong level for reading object encoded as XML - this method calls _readUTF() instead, and so will work if characters have been written explicitly as object data

Specified by:
readLine in interface DataInput
Overrides:
readLine in class ObjectInputStream
IOException

readUTF

public String readUTF()
               throws IOException
Specified by:
readUTF in interface DataInput
Overrides:
readUTF in class ObjectInputStream
IOException

read

public int read()
         throws IOException
Specified by:
read in interface ObjectInput
Overrides:
read in class ObjectInputStream
IOException

read

public int read(byte[] buf,
                int off,
                int len)
         throws IOException
Specified by:
read in interface ObjectInput
Overrides:
read in class ObjectInputStream
IOException

readFully

public void readFully(byte[] buf)
               throws IOException
Specified by:
readFully in interface DataInput
Overrides:
readFully in class ObjectInputStream
IOException

readFully

public void readFully(byte[] buf,
                      int off,
                      int len)
               throws IOException
Specified by:
readFully in interface DataInput
Overrides:
readFully in class ObjectInputStream
IOException

_readUTF

public String _readUTF()
                throws IOException
IOException

readUnshared

public Object readUnshared()
                    throws OptionalDataException,
                           ClassNotFoundException,
                           IOException
Overrides:
readUnshared in class ObjectInputStream
OptionalDataException
ClassNotFoundException
IOException

resolveObject

protected Object resolveObject(Object obj)
                        throws IOException
Override this method, to replace a deserialized object with another

Overrides:
resolveObject in class ObjectInputStream
IOException

enableResolveObject

protected boolean enableResolveObject(boolean enable)
                               throws SecurityException
Overrides:
enableResolveObject in class ObjectInputStream
SecurityException

resolveClass

protected Class resolveClass(ObjectStreamClass osc,
                             String sergeyName)
                      throws IOException,
                             ClassNotFoundException
First attempts to load classes with Thread.currentThread().getContextClassLoader(); if fails, it defaults to the classloader that loaded JSX.Reader. Override this method to implement your own classloading strategy.

IOException
ClassNotFoundException

readClassDescriptor

protected ObjectStreamClass readClassDescriptor()
                                         throws IOException,
                                                ClassNotFoundException
Never called by JSX, so overriding it has no effect. (JOS uses it so you can reimplement the code for parsing an ObjectStreamClass - but JSX doesn't use these, so it makes no sense)

Overrides:
readClassDescriptor in class ObjectInputStream
IOException
ClassNotFoundException

readStreamHeader

protected void readStreamHeader()
                         throws IOException,
                                StreamCorruptedException
Not implemented

Overrides:
readStreamHeader in class ObjectInputStream
IOException
StreamCorruptedException

readObjectOverride

protected Object readObjectOverride()
                             throws IOException,
                                    ClassNotFoundException
Overrides:
readObjectOverride in class ObjectInputStream
IOException
ClassNotFoundException

disableExternalization

public void disableExternalization()
Create object and step through inherited classes +


defaultReadObject

public void defaultReadObject()
                       throws IOException,
                              ClassNotFoundException
Call from within a class's readObject(ObjectInputStream ois) method, so the object is deserialized by the default way. A class can control how its objects are deserialized, by having a readObject(ObjectInputStream ois) method, which JSX will call instead of deserializing it in the default way. The class will then have to explicitly read its custom format (with readInt() etc); to avoid this work, call defaultReadObject instead. This technique is very useful if you want to execute some code just after an object is deserialized, such as initialization code

Overrides:
defaultReadObject in class ObjectInputStream
IOException
ClassNotFoundException

readFields

public ObjectInputStream.GetField readFields()
                                      throws IOException,
                                             ClassNotFoundException
Reads the stream, same as defaultReadObject, but instead of storing into fields, it stores it in a hash that can be queried.
Not implemented: public ObjectStreamClass getObjectStreamClass();

Overrides:
readFields in class ObjectInputStream
IOException
ClassNotFoundException