public class FastSerialize
extends java.lang.Object
See FastSerializable
for caveats on using this approach.
Constructor and Description |
---|
FastSerialize() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
fastDeserialize(byte[] data)
Deserialize an object from a byte array using a custom FastSerializable approach.
|
static java.lang.Object |
fastDeserialize(byte[] data,
java.lang.ClassLoader cl)
Deserialize an object from a byte array using a custom FastSerializable approach.
|
static java.lang.Object |
fastDeserialize(byte[] data,
int offset,
int length)
Deserialize an object from a byte array using a custom FastSerializable approach.
|
static java.lang.Object |
fastDeserialize(byte[] data,
int offset,
int length,
java.lang.ClassLoader cl)
Deserialize an object from a byte array using a custom FastSerializable approach.
|
static byte[] |
fastSerialize(java.lang.Object obj)
Serialize an object to a byte array using a custom FastSerializable approach.
|
static java.lang.Object |
fromStream(java.io.DataInput in)
Deserialize an object using a custom FastSerializable approach to a stream.
|
static java.lang.Object |
fromStream(java.io.DataInput in,
java.lang.ClassLoader cl)
Deserialize an object using a custom FastSerializable approach to a stream.
|
static java.lang.String |
getDeserializeFragment(java.lang.Class type,
java.lang.String source,
java.lang.String dest)
Generate a code fragment that deserializes an expression from a byte array.
|
static java.lang.String |
getDeserializeFragment(java.lang.Class type,
java.lang.String source,
java.lang.String dest,
java.lang.String clExpr)
Generate a code fragment that deserializes an expression from a byte array.
|
static java.lang.String |
getFromStreamFragment(java.lang.Class type,
java.lang.String dest,
java.lang.String stream)
Generate a code fragment that deserializes an expression from a stream.
|
static java.lang.String |
getFromStreamFragment(java.lang.Class type,
java.lang.String dest,
java.lang.String stream,
java.lang.String clExpr)
Generate a code fragment that deserializes an expression from a stream.
|
static java.lang.String |
getSerializeFragment(java.lang.Class type,
java.lang.String source,
java.lang.String dest)
Generate a code fragment that serializes an expression to a byte array.
|
static java.lang.String |
getToStreamFragment(java.lang.Class type,
java.lang.String source,
java.lang.String stream)
Generate a code fragment that serializes an expression to a stream.
|
static boolean |
isSupported(java.lang.Class type)
Check if a given type can be directly handled by
getDeserializeFragment(java.lang.Class, java.lang.String, java.lang.String) etc. |
static ProfileID |
readProfileID(java.io.DataInput in,
java.lang.ClassLoader cl) |
static java.lang.String |
readString(java.io.DataInput inStream) |
static java.lang.Object |
standardDeserialize(byte[] byteArray)
Deserialize an object from a byte array using the standard Serializable approach.
|
static java.lang.Object |
standardDeserialize(byte[] byteArray,
java.lang.ClassLoader classLoader)
Deserialize an object from a byte array using the standard Serializable approach.
|
static java.lang.Object |
standardDeserialize(byte[] byteArray,
int offset,
int length)
Deserialize an object from a byte array using the standard Serializable approach.
|
static java.lang.Object |
standardDeserialize(byte[] byteArray,
int offset,
int length,
java.lang.ClassLoader classLoader)
Deserialize an object from a byte array using the standard Serializable approach.
|
static byte[] |
standardSerialize(java.lang.Object toSerialize)
Serialize an object to a byte array using the standard Serializable approach.
|
static void |
toStream(java.lang.Object obj,
java.io.DataOutput out)
Serialize an object using a custom FastSerializable approach to a stream.
|
static void |
writeProfileID(java.io.DataOutput out,
ProfileID profileID) |
static void |
writeString(java.lang.String value,
java.io.DataOutput outStream) |
public static java.lang.String getToStreamFragment(java.lang.Class type, java.lang.String source, java.lang.String stream)
type
- the type of the expression to be serializedsource
- an expression evaluating to the value to serializestream
- an expression evaluating to the stream to serialize to. This should be a java.io.DataOutput object.public static java.lang.String getFromStreamFragment(java.lang.Class type, java.lang.String dest, java.lang.String stream)
getToStreamFragment(java.lang.Class, java.lang.String, java.lang.String)
.
The thread context classloader (at the time of execution of the generated fragment!)
is used for deserialization.type
- the type of the expression to be deserializeddest
- a lvalue to assign the deserialized value tostream
- an expression evaluating to the stream to deserialize from. This should be a java.io.DataInput object.public static java.lang.String getFromStreamFragment(java.lang.Class type, java.lang.String dest, java.lang.String stream, java.lang.String clExpr)
getToStreamFragment(java.lang.Class, java.lang.String, java.lang.String)
.type
- the type of the expression to be deserializeddest
- a lvalue to assign the deserialized value tostream
- an expression evaluating to the stream to deserialize from. This should be a java.io.DataInput object.clExpr
- a classloader expression fragment to use as the deserialization classloaderpublic static java.lang.String getSerializeFragment(java.lang.Class type, java.lang.String source, java.lang.String dest)
type
- the type of the expression to be deserializedsource
- an expression evaluating to the value to serializedest
- a lvalue to assign the resulting bytearray topublic static java.lang.String getDeserializeFragment(java.lang.Class type, java.lang.String source, java.lang.String dest)
type
- the type of the expression to be deserializedsource
- an expression evaluating to the byte array to deserialize fromdest
- a lvalue to assign the deserialized value topublic static java.lang.String getDeserializeFragment(java.lang.Class type, java.lang.String source, java.lang.String dest, java.lang.String clExpr)
type
- the type of the expression to be deserializedsource
- an expression evaluating to the byte array to deserialize fromdest
- a lvalue to assign the deserialized value toclExpr
- a classloader expression fragment to use as the deserialization classloaderpublic static boolean isSupported(java.lang.Class type)
getDeserializeFragment(java.lang.Class, java.lang.String, java.lang.String)
etc.type
- the type to check.type
will be directly handled; false if it will use standard serializationpublic static final java.lang.String readString(java.io.DataInput inStream) throws java.io.IOException
java.io.IOException
public static final void writeString(java.lang.String value, java.io.DataOutput outStream) throws java.io.IOException
java.io.IOException
public static byte[] standardSerialize(java.lang.Object toSerialize) throws java.io.IOException
toSerialize
- the object to serializejava.io.IOException
- if serialization failedpublic static java.lang.Object standardDeserialize(byte[] byteArray) throws java.io.IOException
byteArray
- the serialized data to deserializejava.io.IOException
- if deserialization failedpublic static java.lang.Object standardDeserialize(byte[] byteArray, java.lang.ClassLoader classLoader) throws java.io.IOException
byteArray
- the serialized data to deserializeclassLoader
- the class loader to be used during deserialisationjava.io.IOException
- if deserialization failedpublic static java.lang.Object standardDeserialize(byte[] byteArray, int offset, int length) throws java.io.IOException
byteArray
- the serialized data to deserializeoffset
- the offset within byteArray of the datalength
- the length of data within byteArrayjava.io.IOException
- if deserialization failedpublic static java.lang.Object standardDeserialize(byte[] byteArray, int offset, int length, java.lang.ClassLoader classLoader) throws java.io.IOException
byteArray
- the serialized data to deserializeoffset
- the offset within byteArray of the datalength
- the length of data within byteArrayclassLoader
- the class loader to be used during deserialisationjava.io.IOException
- if deserialization failedpublic static byte[] fastSerialize(java.lang.Object obj) throws java.io.IOException
fastDeserialize(byte[])
obj
- the object to serializejava.io.IOException
- if serialization failedpublic static java.lang.Object fastDeserialize(byte[] data) throws java.io.IOException
data
- the serialized data (from fastSerialize(java.lang.Object)
) to deserializejava.io.IOException
- if deserialization failedpublic static java.lang.Object fastDeserialize(byte[] data, int offset, int length) throws java.io.IOException
data
- the serialized data (from fastSerialize(java.lang.Object)
) to deserializeoffset
- the offset within byteArray of the datalength
- the length of data within byteArrayjava.io.IOException
- if deserialization failedpublic static java.lang.Object fastDeserialize(byte[] data, java.lang.ClassLoader cl) throws java.io.IOException
data
- the serialized data (from fastSerialize(java.lang.Object)
) to deserializejava.io.IOException
- if deserialization failedpublic static java.lang.Object fastDeserialize(byte[] data, int offset, int length, java.lang.ClassLoader cl) throws java.io.IOException
data
- the serialized data (from fastSerialize(java.lang.Object)
) to deserializeoffset
- the offset within byteArray of the datalength
- the length of data within byteArrayjava.io.IOException
- if deserialization failedpublic static void toStream(java.lang.Object obj, java.io.DataOutput out) throws java.io.IOException
fromStream(java.io.DataInput)
.obj
- the object to serializeout
- the stream to serialize tojava.io.IOException
- if serialization failspublic static java.lang.Object fromStream(java.io.DataInput in) throws java.io.IOException
toStream(java.lang.Object, java.io.DataOutput)
. The thread context classloader
is used for deserialization.in
- the stream to deserializejava.io.IOException
- if deserialization failspublic static java.lang.Object fromStream(java.io.DataInput in, java.lang.ClassLoader cl) throws java.io.IOException
toStream(java.lang.Object, java.io.DataOutput)
.in
- the stream to deserializecl
- the classloader to use for deserializationjava.io.IOException
- if deserialization failspublic static ProfileID readProfileID(java.io.DataInput in, java.lang.ClassLoader cl) throws java.io.IOException
java.io.IOException
public static void writeProfileID(java.io.DataOutput out, ProfileID profileID) throws java.io.IOException
java.io.IOException