org.clazzes.remoting.marshal.impl
Class JAVAMarshaler

java.lang.Object
  extended by org.clazzes.remoting.marshal.impl.MarshalerSupport
      extended by org.clazzes.remoting.marshal.impl.JAVAMarshaler
All Implemented Interfaces:
Marshaler

public class JAVAMarshaler
extends MarshalerSupport

The default implementation of the marshaler, which uses an ObjectInputStreamWithClassLoader and an ObjectOutputStream for deserialization and serialization.

Author:
wglas

Field Summary
protected  java.io.ObjectInputStream ois
           
protected  java.io.ObjectOutputStream oos
           
 
Constructor Summary
JAVAMarshaler()
          Default constructor, which set the output and input buffer size to 0.
JAVAMarshaler(int outputBufferSize, int inputBufferSize)
          Construct a JAVAMarshaler, with given input and output buffer sizes.
 
Method Summary
 void close()
          Close the underlying transport and prepare the marshaler for calling Marshaler.setup(OutputStream, InputStream, ClassLoader) again.
 java.lang.Object readObject()
          Read the next object from the input stream.
 void reset()
          Reset the state of the serializer.
 void setup(java.io.OutputStream os, java.io.InputStream is, java.lang.ClassLoader inputClassLoader)
          Set up the marshaler for operation.
protected  java.io.ObjectInputStream setupObjectInputStream(java.io.InputStream is, java.lang.ClassLoader inputClassLoader)
           
protected  java.io.ObjectOutputStream setupObjectOutputStream(java.io.OutputStream os)
           
 void writeObject(java.lang.Object obj)
          Write an object to the underlying transport.
 
Methods inherited from class org.clazzes.remoting.marshal.impl.MarshalerSupport
getInputBufferSize, getOutputBufferSize, prepareInputStream, prepareOutputStream, setInputBufferSize, setOutputBufferSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ois

protected java.io.ObjectInputStream ois

oos

protected java.io.ObjectOutputStream oos
Constructor Detail

JAVAMarshaler

public JAVAMarshaler()
Default constructor, which set the output and input buffer size to 0.


JAVAMarshaler

public JAVAMarshaler(int outputBufferSize,
                     int inputBufferSize)
Construct a JAVAMarshaler, with given input and output buffer sizes.

Parameters:
outputBufferSize - The size of the output buffer to use.
inputBufferSize - The size of the input buffer to use.
Method Detail

setupObjectOutputStream

protected java.io.ObjectOutputStream setupObjectOutputStream(java.io.OutputStream os)
                                                      throws java.io.IOException
Parameters:
os - The output stream returned by MarshalerSupport.prepareOutputStream(OutputStream).
Returns:
An object output stream for writing objects.
Throws:
java.io.IOException - Upon errors.

setupObjectInputStream

protected java.io.ObjectInputStream setupObjectInputStream(java.io.InputStream is,
                                                           java.lang.ClassLoader inputClassLoader)
                                                    throws java.io.IOException
Parameters:
is - The input stream as return by MarshalerSupport.prepareInputStream(InputStream).
inputClassLoader - The class loader to use for deserialization.
Returns:
An ObjectInputStream for the marshaler.
Throws:
java.io.IOException - Upon errors setting up the ObjectInputStream.

setup

public void setup(java.io.OutputStream os,
                  java.io.InputStream is,
                  java.lang.ClassLoader inputClassLoader)
           throws java.io.IOException
Description copied from interface: Marshaler
Set up the marshaler for operation. Implementations must guarantee, that both, the input and the output stream are closed, when an excpetion is thrown.

Parameters:
os - The output stream to write to.
is - The input stream to read from.
inputClassLoader - The ClassLoader to use for deserialized instances.
Throws:
java.io.IOException - Upon errors setting up the streams.

readObject

public java.lang.Object readObject()
                            throws java.lang.ClassNotFoundException,
                                   java.io.IOException
Description copied from interface: Marshaler
Read the next object from the input stream. It is the responsibility of the caller, that this method is only called from a single thread at a time. The implementation need not be synchronized.

Returns:
The next object on the input stream.
Throws:
java.lang.ClassNotFoundException - If the underlying class loader was unable to find the class of a serialized object.
java.io.IOException - Upon transport errors.

reset

public void reset()
           throws java.io.IOException
Description copied from interface: Marshaler
Reset the state of the serializer. This incurs the cleanup of the object cache, which ensures, that the same instance of a class is serialized as reference rather than being serialized a second time.

Throws:
java.io.IOException - Upon transport errors.

writeObject

public void writeObject(java.lang.Object obj)
                 throws java.io.IOException
Description copied from interface: Marshaler
Write an object to the underlying transport. This method must be implemented in a synchronized manner in order to allow writing objects from two concurrent threads.

Parameters:
obj - The object to write.
Throws:
java.io.IOException - Upon transport errors.

close

public void close()
Description copied from interface: Marshaler
Close the underlying transport and prepare the marshaler for calling Marshaler.setup(OutputStream, InputStream, ClassLoader) again. This method should be implemented in a fashion that is tolerant for an incomplete setup of the marshaler. It should even be possible to call close() twice on a single marshaler object.



Copyright © 2010. All Rights Reserved.