JSX
Class ObjectReader

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.ObjectInputStream
          extended by JSX.ObjectReader
All Implemented Interfaces:
java.io.Closeable, java.io.DataInput, java.io.ObjectInput, java.io.ObjectStreamConstants

public class ObjectReader
extends java.io.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
           
 
Nested classes/interfaces inherited from class java.io.ObjectInputStream
java.io.ObjectInputStream.GetField
 
Field Summary
 
Fields inherited from interface java.io.ObjectStreamConstants
baseWireHandle, PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, SC_BLOCK_DATA, SC_ENUM, 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_ENUM, TC_EXCEPTION, TC_LONGSTRING, TC_MAX, TC_NULL, TC_OBJECT, TC_PROXYCLASSDESC, TC_REFERENCE, TC_RESET, TC_STRING
 
Constructor Summary
ObjectReader(DataReaderI dataReader)
           
ObjectReader(DataReaderI dataReader, java.lang.ClassLoader cl)
          Pass in a classloader for JSX to lookup classes that are being deserialized.
ObjectReader(java.io.InputStream in)
           
ObjectReader(java.io.InputStream in, java.lang.ClassLoader cl)
          Pass in a classloader for JSX to lookup classes that are being deserialized.
ObjectReader(java.io.Reader reader)
           
ObjectReader(java.io.Reader reader, java.lang.ClassLoader cl)
          Pass in a classloader for JSX to lookup classes that are being deserialized.
 
Method Summary
 java.lang.String _readUTF()
           
 void add(java.lang.Class targetClass, java.lang.Class mementoClass)
           
 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)
           
 java.util.HashMap getHash()
           
static void main(java.lang.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  java.io.ObjectStreamClass readClassDescriptor()
          Never called by JSX, so overriding it has no effect.
 double readDouble()
           
 java.io.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()
           
 java.lang.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  java.lang.Object readObjectOverride()
           
 short readShort()
           
protected  void readStreamHeader()
          Not implemented
 java.lang.Object readUnshared()
           
 int readUnsignedByte()
           
 int readUnsignedShort()
           
 java.lang.String readUTF()
           
 void registerValidation(java.io.ObjectInputValidation obj, int prio)
           
protected  java.lang.Class resolveClass(java.io.ObjectStreamClass osc, java.lang.String sergeyName)
          First attempts to load classes with Thread.currentThread().getContextClassLoader(); if fails, it defaults to the classloader that loaded JSX.Reader.
protected  java.lang.Object resolveObject(java.lang.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(java.io.InputStream in)
             throws java.io.IOException
Throws:
java.io.IOException

ObjectReader

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

Throws:
java.io.IOException

ObjectReader

public ObjectReader(java.io.Reader reader)
             throws java.io.IOException
Throws:
java.io.IOException

ObjectReader

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

Throws:
java.io.IOException

ObjectReader

public ObjectReader(DataReaderI dataReader)
             throws java.io.IOException
Throws:
java.io.IOException

ObjectReader

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

Throws:
java.io.IOException
Method Detail

main

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

Throws:
java.io.IOException
java.lang.ClassNotFoundException

getHash

public java.util.HashMap getHash()

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Specified by:
close in interface java.io.ObjectInput
Overrides:
close in class java.io.ObjectInputStream
Throws:
java.io.IOException

available

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

Specified by:
available in interface java.io.ObjectInput
Overrides:
available in class java.io.ObjectInputStream
Throws:
java.io.IOException

registerValidation

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

readBoolean

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

readByte

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

readChar

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

readUnsignedByte

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

readShort

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

readUnsignedShort

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

readInt

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

readLong

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

readFloat

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

readDouble

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

readLine

public java.lang.String readLine()
                          throws java.io.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 java.io.DataInput
Overrides:
readLine in class java.io.ObjectInputStream
Throws:
java.io.IOException

readUTF

public java.lang.String readUTF()
                         throws java.io.IOException
Specified by:
readUTF in interface java.io.DataInput
Overrides:
readUTF in class java.io.ObjectInputStream
Throws:
java.io.IOException

read

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

read

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

readFully

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

readFully

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

_readUTF

public java.lang.String _readUTF()
                          throws java.io.IOException
Throws:
java.io.IOException

readUnshared

public java.lang.Object readUnshared()
                              throws java.io.OptionalDataException,
                                     java.lang.ClassNotFoundException,
                                     java.io.IOException
Overrides:
readUnshared in class java.io.ObjectInputStream
Throws:
java.io.OptionalDataException
java.lang.ClassNotFoundException
java.io.IOException

resolveObject

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

Overrides:
resolveObject in class java.io.ObjectInputStream
Throws:
java.io.IOException

enableResolveObject

protected boolean enableResolveObject(boolean enable)
                               throws java.lang.SecurityException
Overrides:
enableResolveObject in class java.io.ObjectInputStream
Throws:
java.lang.SecurityException

resolveClass

protected java.lang.Class resolveClass(java.io.ObjectStreamClass osc,
                                       java.lang.String sergeyName)
                                throws java.io.IOException,
                                       java.lang.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.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

readClassDescriptor

protected java.io.ObjectStreamClass readClassDescriptor()
                                                 throws java.io.IOException,
                                                        java.lang.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 java.io.ObjectInputStream
Throws:
java.io.IOException
java.lang.ClassNotFoundException

readStreamHeader

protected void readStreamHeader()
                         throws java.io.IOException,
                                java.io.StreamCorruptedException
Not implemented

Overrides:
readStreamHeader in class java.io.ObjectInputStream
Throws:
java.io.IOException
java.io.StreamCorruptedException

readObjectOverride

protected java.lang.Object readObjectOverride()
                                       throws java.io.IOException,
                                              java.lang.ClassNotFoundException
Overrides:
readObjectOverride in class java.io.ObjectInputStream
Throws:
java.io.IOException
java.lang.ClassNotFoundException

disableExternalization

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


add

public void add(java.lang.Class targetClass,
                java.lang.Class mementoClass)

defaultReadObject

public void defaultReadObject()
                       throws java.io.IOException,
                              java.lang.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 java.io.ObjectInputStream
Throws:
java.io.IOException
java.lang.ClassNotFoundException

readFields

public java.io.ObjectInputStream.GetField readFields()
                                              throws java.io.IOException,
                                                     java.lang.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 java.io.ObjectInputStream
Throws:
java.io.IOException
java.lang.ClassNotFoundException