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.Externalizable
Serialized 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 class
SerializedData.AccesibleByteArrayOutputStream
This class exists purely for performance reasons.private class
SerializedData.BasicInputStreamFactory
Implementation of theInputStreamFactory
to create aObjectInputStream
.private static class
SerializedData.ExtClass
This class exists because the main class cannot have a no-arg constructor as required by externalizable.static interface
SerializedData.InputStreamFactory
Factory for creating object input streams.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
objectToString
The string representation of the object.private byte[]
serializedData
The 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.Object
get()
Deserializes the object from the byte[] array and returns it.java.lang.Object
get(SerializedData.InputStreamFactory factory)
Deserializes the object from the byte[] array and returns it.java.lang.String
getObjectToString()
Returns the string form of an object.byte[]
getSerializedData()
Returns the binary serialized object.void
readExternal(java.io.ObjectInput in)
void
writeExternal(java.io.ObjectOutput out)
java.lang.Object
writeReplace()
Replaces this object with another during serialization.
-
-
-
Constructor Detail
-
SerializedData
public SerializedData(java.lang.Object obj, boolean storeToString) throws java.io.NotSerializableException, java.io.IOException
This is the public used constructor. It takes an object and attempts to serialize it.- Parameters:
obj
- the Object to Serialize.storeToString
- iftrue
will 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.IOException
Deserializes 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:
writeExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
- Specified by:
readExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
writeReplace
public java.lang.Object writeReplace() throws java.io.ObjectStreamException
Replaces this object with another during serialization.- Returns:
- the replacement.
- Throws:
java.io.ObjectStreamException
-
-