it.unimo.dbgroup.momis.XmlTools
Class XmlObjectInput

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.ObjectInputStream
          extended byit.unimo.dbgroup.momis.XmlTools.XmlObjectInput
All Implemented Interfaces:
java.io.DataInput, java.io.ObjectInput, java.io.ObjectStreamConstants

public final class XmlObjectInput
extends java.io.ObjectInputStream

XmlReader wrapper that extends ObjectInputStream.

This class is used by XmlReader to call custom readObject(ObjectInputStream in) methods.

You can also use this class as a stand alone object input deserializer.

This wrapper is provided to extends functionalities of XmlReader to all java objects. You can think to XmlObjectInput as a part of XmlReader or as stand alone object that extends XmlReader.

Remember that this class is a wrapper, so use XmlReader if you can, it is more efficient.

For more details see XmlReader methods.

See Also:
XmlReader

Nested Class Summary
 
Nested classes inherited from class java.io.ObjectInputStream
java.io.ObjectInputStream.GetField
 
Field Summary
private  java.io.InputStream _in
          Reference to the input stream.
private  XmlReader _rdr
          Reference to the wrapped XmlReader.
 
Fields inherited from class java.io.ObjectInputStream
 
Fields inherited from class java.io.InputStream
 
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
XmlObjectInput(java.io.InputStream in)
          Creates a stand alone wrapper.
XmlObjectInput(XmlReader rdr)
          Creates a wrapper and uses the specified XmlReader object.
 
Method Summary
 int available()
          Returns the number of bytes that can be read without blocking.
 void close()
          Close the input stream if it was supplied with the proper constructor.
 void defaultReadObject()
          Read the non-static and non-transient fields of the current class from the DOM tree.
protected  boolean enableResolveObject(boolean enable)
          Does nothing.
 XmlReader getReader()
          Returns the XmlReader object that this instance is wrapping.
 int read()
          Reads a byte of data.
 int read(byte[] b, int off, int len)
          Reads into an array of bytes.
 boolean readBoolean()
          Reads in a boolean.
 byte readByte()
          Reads in a byte.
 char readChar()
          Reads a 16 bit char.
protected  java.io.ObjectStreamClass readClassDescriptor()
          Does nothing.
 double readDouble()
          Reads a 64 bit double.
 java.io.ObjectInputStream.GetField readFields()
          Does nothing.
 float readFloat()
          Reads a 32 bit float.
 void readFully(byte[] data)
          Reads bytes as specified in DataInput interface.
 void readFully(byte[] data, int offset, int size)
          Reads bytes as specified in DataInput interface.
 int readInt()
          Reads a 32 bit integer.
 long readLong()
          Reads a 64 bit long.
protected  java.lang.Object readObjectOverride()
          Overridden implementation for readObject method.
 short readShort()
          Reads a 16 bit short.
protected  void readStreamHeader()
          Does nothing.
 int readUnsignedByte()
          Reads an unsigned 8 bit byte.
 int readUnsignedShort()
          Reads an unsigned 16 bit short.
 java.lang.String readUTF()
          Reads a UTF format String.
 void registerValidation(java.io.ObjectInputValidation obj, int prio)
          Register an object to be validated before the graph is returned.
protected  java.lang.Class resolveClass(java.io.ObjectStreamClass v)
          Does nothing.
protected  java.lang.Object resolveObject(java.lang.Object obj)
          Does nothing.
protected  java.lang.Class resolveProxyClass(java.lang.String[] interfaces)
          Does nothing.
 int skipBytes(int len)
          Does nothing.
 
Methods inherited from class java.io.ObjectInputStream
readLine, readObject, readUnshared
 
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
 

Field Detail

_in

private java.io.InputStream _in
Reference to the input stream.


_rdr

private XmlReader _rdr
Reference to the wrapped XmlReader.

Constructor Detail

XmlObjectInput

public XmlObjectInput(java.io.InputStream in)
               throws java.io.IOException,
                      XmlToolsException
Creates a stand alone wrapper.

Parameters:
in - InputStream with XML data to convert in a DOM tree.

XmlObjectInput

public XmlObjectInput(XmlReader rdr)
               throws java.io.IOException
Creates a wrapper and uses the specified XmlReader object.

After this constructor returns, the calling method should call XmlReader.setObjectInputWrapper(); with the new XmlObjectInput as parameter to ensure coerence.

Parameters:
rdr - XmlReader that must be used.
Method Detail

resolveClass

protected java.lang.Class resolveClass(java.io.ObjectStreamClass v)
                                throws java.io.IOException,
                                       java.lang.ClassNotFoundException
Does nothing. Returns null.

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

resolveProxyClass

protected java.lang.Class resolveProxyClass(java.lang.String[] interfaces)
                                     throws java.io.IOException,
                                            java.lang.ClassNotFoundException
Does nothing. Returns null.

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

resolveObject

protected java.lang.Object resolveObject(java.lang.Object obj)
                                  throws java.io.IOException
Does nothing. Returns the passed object.

Throws:
java.io.IOException

enableResolveObject

protected boolean enableResolveObject(boolean enable)
                               throws java.lang.SecurityException
Does nothing. Returns always false.

Throws:
java.lang.SecurityException

readStreamHeader

protected void readStreamHeader()
                         throws java.io.IOException,
                                java.io.StreamCorruptedException
Does nothing.

Throws:
java.io.IOException
java.io.StreamCorruptedException

readClassDescriptor

protected java.io.ObjectStreamClass readClassDescriptor()
                                                 throws java.io.IOException,
                                                        java.lang.ClassNotFoundException
Does nothing. Returns null.

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

readObjectOverride

protected java.lang.Object readObjectOverride()
                                       throws java.io.OptionalDataException,
                                              java.lang.ClassNotFoundException,
                                              java.io.IOException
Overridden implementation for readObject method.
This method will call XmlReader.readObject() to deserialize an objects graph.

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

getReader

public XmlReader getReader()
Returns the XmlReader object that this instance is wrapping.


available

public int available()
              throws java.io.IOException
Returns the number of bytes that can be read without blocking.
In this implementation the DOM tree is already in memory, so Integer.MAX_VALUE is returned to indicate that none of the reading methods will block.

Throws:
java.io.IOException

defaultReadObject

public void defaultReadObject()
                       throws java.io.IOException,
                              java.lang.ClassNotFoundException,
                              java.io.NotActiveException
Read the non-static and non-transient fields of the current class from the DOM tree.

This method will call XmlReader.defaultRead().

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

readFields

public java.io.ObjectInputStream.GetField readFields()
                                              throws java.io.IOException,
                                                     java.lang.ClassNotFoundException,
                                                     java.io.NotActiveException
Does nothing. Returns null.

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

registerValidation

public void registerValidation(java.io.ObjectInputValidation obj,
                               int prio)
                        throws java.io.NotActiveException,
                               java.io.InvalidObjectException
Register an object to be validated before the graph is returned.

This method will call XmlReader.registerValidation method.
Typically, a readObject method will register the object with the stream so that when all of the objects are restored a final set of validations can be performed.

Parameters:
obj - the object to receive the validation callback.
prio - controls the order of callbacks;zero is a good default. Use higher numbers to be called back earlier, lower numbers for later callbacks. Within a priority, callbacks are processed in no particular order.
Throws:
java.io.NotActiveException - - The Reader is not currently reading objects so it is invalid to register a callback.
java.io.InvalidObjectException - - The validation object is null.

read

public int read()
         throws java.io.IOException
Reads a byte of data. This method will never block.

Throws:
java.io.IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads into an array of bytes.

Parameters:
b - the buffer into which the data is read
off - the start offset of the data
len - the maximum number of bytes read
Returns:
the actual number of bytes read.
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Close the input stream if it was supplied with the proper constructor.

Throws:
java.io.IOException

readBoolean

public boolean readBoolean()
                    throws java.io.IOException
Reads in a boolean.

See XmlReader.readBoolean for more details.

Throws:
java.io.IOException

readByte

public byte readByte()
              throws java.io.IOException
Reads in a byte.

See XmlReader.readByte for more details.

Throws:
java.io.IOException

readUnsignedByte

public int readUnsignedByte()
                     throws java.io.IOException
Reads an unsigned 8 bit byte.

Throws:
java.io.IOException

readShort

public short readShort()
                throws java.io.IOException
Reads a 16 bit short.

See XmlReader.readShort for more details.

Throws:
java.io.IOException

readUnsignedShort

public int readUnsignedShort()
                      throws java.io.IOException
Reads an unsigned 16 bit short.

Throws:
java.io.IOException

readChar

public char readChar()
              throws java.io.IOException
Reads a 16 bit char.

See XmlReader.readChar for more details.

Throws:
java.io.IOException

readInt

public int readInt()
            throws java.io.IOException
Reads a 32 bit integer.

See XmlReader.readInt for more details.

Throws:
java.io.IOException

readLong

public long readLong()
              throws java.io.IOException
Reads a 64 bit long.

See XmlReader.readLong for more details.

Throws:
java.io.IOException

readFloat

public float readFloat()
                throws java.io.IOException
Reads a 32 bit float.

See XmlReader.readFloat for more details.

Throws:
java.io.IOException

readDouble

public double readDouble()
                  throws java.io.IOException
Reads a 64 bit double.

See XmlReader.readDouble for more details.

Throws:
java.io.IOException

readFully

public void readFully(byte[] data)
               throws java.io.IOException
Reads bytes as specified in DataInput interface.

Please note that if in the source XML there is a string in the current position, that string is converted in a bytes array.

Any other elements will cause an exception.
Use this method to read data written with the following methods only:
XmlObjectOutput.write(byte[] b,int off, int len)
XmlObjectOutput.write(byte[] b)
XmlObjectOutput.writeUTF(String s)

Parameters:
data - the buffer into which the data is read
Throws:
java.io.IOException

readFully

public void readFully(byte[] data,
                      int offset,
                      int size)
               throws java.io.IOException
Reads bytes as specified in DataInput interface.

Please note that if in the source XML there is a string in the current position, that string is converted in a bytes array.

Any other elements will cause an exception.
Use this method to read data written with the following methods only:
XmlObjectOutput.write(byte[] b,int off, int len)
XmlObjectOutput.write(byte[] b)
XmlObjectOutput.writeUTF(String s)

Parameters:
data - the buffer into which the data is read
offset - the start offset of the data
size - the maximum number of bytes to read
Throws:
java.io.IOException

skipBytes

public int skipBytes(int len)
              throws java.io.IOException
Does nothing. returns 0.

Throws:
java.io.IOException

readUTF

public java.lang.String readUTF()
                         throws java.io.IOException
Reads a UTF format String.

Please note that id other object element are encoutered this method will throw an exception.

Throws:
java.io.IOException


Universita' di Modena e Reggio Emilia