Package org.jcsp.net.dynamic
Class SerializedData
- java.lang.Object
-
- org.jcsp.net.dynamic.SerializedData
-
- All Implemented Interfaces:
java.io.Externalizable,java.io.Serializable
class SerializedData extends java.lang.Object implements java.io.ExternalizableSerialized form of an object as as part of aDynamicClassLoaderMessage. The object is serialized to a byte array for transfer to another node. This will allow the message to be deserialized to obtain the JFTP reference even if the class held here is not available. When the relevant class has been loaded the data from the byte array can be deserialized.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classSerializedData.AccesibleByteArrayOutputStreamThis class exists purely for performance reasons.private classSerializedData.BasicInputStreamFactoryImplementation of theInputStreamFactoryto create aObjectInputStream.private static classSerializedData.ExtClassThis class exists because the main class cannot have a no-arg constructor as required by externalizable.static interfaceSerializedData.InputStreamFactoryFactory for creating object input streams.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringobjectToStringThe string representation of the object.private byte[]serializedDataThe binary form of the object in this message.
-
Constructor Summary
Constructors Constructor Description SerializedData(byte[] data, java.lang.String objectToString)A private constructor used during the deserialization process of this object.SerializedData(java.lang.Object obj, boolean storeToString)This is the public used constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectget()Deserializes the object from the byte[] array and returns it.java.lang.Objectget(SerializedData.InputStreamFactory factory)Deserializes the object from the byte[] array and returns it.java.lang.StringgetObjectToString()Returns the string form of an object.byte[]getSerializedData()Returns the binary serialized object.voidreadExternal(java.io.ObjectInput in)voidwriteExternal(java.io.ObjectOutput out)java.lang.ObjectwriteReplace()Replaces this object with another during serialization.
-
-
-
Constructor Detail
-
SerializedData
public SerializedData(java.lang.Object obj, boolean storeToString) throws java.io.NotSerializableException, java.io.IOExceptionThis is the public used constructor. It takes an object and attempts to serialize it.- Parameters:
obj- the Object to Serialize.storeToString- iftruewill create a string representation of the serialized object.- Throws:
java.io.NotSerializableException- If obj is not Serializable.java.io.IOException- if an IO error occurs during Serialization, should not happen unless there is a bug.
-
SerializedData
SerializedData(byte[] data, java.lang.String objectToString)A private constructor used during the deserialization process of this object. Externalizable objects require a no-arg constructor so a replacement object is serialized in this object's place. On deserialization, this object is reconstructed using this constructor.- Parameters:
data- a byte[] containing the serialized data of the object that this object is holding.objectToString- The toString value of the stored object.
-
-
Method Detail
-
getSerializedData
public byte[] getSerializedData()
Returns the binary serialized object.
-
get
public java.lang.Object get() throws java.lang.ClassNotFoundException, java.io.IOExceptionDeserializes the object from the byte[] array and returns it.- Throws:
java.lang.ClassNotFoundException- if the class is not available locally and should be requested.java.io.IOException- if there is a problem with the stream.
-
get
public java.lang.Object get(SerializedData.InputStreamFactory factory) throws java.lang.ClassNotFoundException, java.io.IOException
Deserializes the object from the byte[] array and returns it.- Parameters:
factory- the factory for creating the input stream.- Throws:
java.lang.ClassNotFoundException- if the class is not available locally and should be requested.java.io.IOException- if there is a problem with the stream.
-
getObjectToString
public java.lang.String getObjectToString()
Returns the string form of an object.
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException- Specified by:
writeExternalin interfacejava.io.Externalizable- Throws:
java.io.IOException
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException- Specified by:
readExternalin interfacejava.io.Externalizable- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
writeReplace
public java.lang.Object writeReplace() throws java.io.ObjectStreamExceptionReplaces this object with another during serialization.- Returns:
- the replacement.
- Throws:
java.io.ObjectStreamException
-
-