public class FastSerialize extends Object
See FastSerializable
for caveats on using this approach.
Constructor and Description |
---|
FastSerialize() |
Modifier and Type | Method and Description |
---|---|
static Object |
fastDeserialize(byte[] data)
Deserialize an object from a byte array using a custom FastSerializable approach.
|
static Object |
fastDeserialize(byte[] data,
ClassLoader cl)
Deserialize an object from a byte array using a custom FastSerializable approach.
|
static Object |
fastDeserialize(byte[] data,
int offset,
int length)
Deserialize an object from a byte array using a custom FastSerializable approach.
|
static Object |
fastDeserialize(byte[] data,
int offset,
int length,
ClassLoader cl)
Deserialize an object from a byte array using a custom FastSerializable approach.
|
static byte[] |
fastSerialize(Object obj)
Serialize an object to a byte array using a custom FastSerializable approach.
|
static Object |
fromStream(DataInput in)
Deserialize an object using a custom FastSerializable approach to a stream.
|
static Object |
fromStream(DataInput in,
ClassLoader cl)
Deserialize an object using a custom FastSerializable approach to a stream.
|
static String |
getDeserializeFragment(Class type,
String source,
String dest)
Generate a code fragment that deserializes an expression from a byte array.
|
static String |
getDeserializeFragment(Class type,
String source,
String dest,
String clExpr)
Generate a code fragment that deserializes an expression from a byte array.
|
static String |
getFromStreamFragment(Class type,
String dest,
String stream)
Generate a code fragment that deserializes an expression from a stream.
|
static String |
getFromStreamFragment(Class type,
String dest,
String stream,
String clExpr)
Generate a code fragment that deserializes an expression from a stream.
|
static String |
getSerializeFragment(Class type,
String source,
String dest)
Generate a code fragment that serializes an expression to a byte array.
|
static String |
getToStreamFragment(Class type,
String source,
String stream)
Generate a code fragment that serializes an expression to a stream.
|
static boolean |
isSupported(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(DataInput in,
ClassLoader cl) |
static String |
readString(DataInput inStream) |
static Object |
standardDeserialize(byte[] byteArray)
Deserialize an object from a byte array using the standard Serializable approach.
|
static Object |
standardDeserialize(byte[] byteArray,
ClassLoader classLoader)
Deserialize an object from a byte array using the standard Serializable approach.
|
static Object |
standardDeserialize(byte[] byteArray,
int offset,
int length)
Deserialize an object from a byte array using the standard Serializable approach.
|
static Object |
standardDeserialize(byte[] byteArray,
int offset,
int length,
ClassLoader classLoader)
Deserialize an object from a byte array using the standard Serializable approach.
|
static byte[] |
standardSerialize(Object toSerialize)
Serialize an object to a byte array using the standard Serializable approach.
|
static void |
toStream(Object obj,
DataOutput out)
Serialize an object using a custom FastSerializable approach to a stream.
|
static void |
writeProfileID(DataOutput out,
ProfileID profileID) |
static void |
writeString(String value,
DataOutput outStream) |
public static String getToStreamFragment(Class type, String source, 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 String getFromStreamFragment(Class type, String dest, 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 String getFromStreamFragment(Class type, String dest, String stream, 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 String getSerializeFragment(Class type, String source, 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 String getDeserializeFragment(Class type, String source, 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 String getDeserializeFragment(Class type, String source, String dest, 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(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 String readString(DataInput inStream) throws IOException
IOException
public static final void writeString(String value, DataOutput outStream) throws IOException
IOException
public static byte[] standardSerialize(Object toSerialize) throws IOException
toSerialize
- the object to serializeIOException
- if serialization failedpublic static Object standardDeserialize(byte[] byteArray) throws IOException
byteArray
- the serialized data to deserializeIOException
- if deserialization failedpublic static Object standardDeserialize(byte[] byteArray, ClassLoader classLoader) throws IOException
byteArray
- the serialized data to deserializeclassLoader
- the class loader to be used during deserialisationIOException
- if deserialization failedpublic static Object standardDeserialize(byte[] byteArray, int offset, int length) throws IOException
byteArray
- the serialized data to deserializeoffset
- the offset within byteArray of the datalength
- the length of data within byteArrayIOException
- if deserialization failedpublic static Object standardDeserialize(byte[] byteArray, int offset, int length, ClassLoader classLoader) throws 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 deserialisationIOException
- if deserialization failedpublic static byte[] fastSerialize(Object obj) throws IOException
fastDeserialize(byte[])
obj
- the object to serializeIOException
- if serialization failedpublic static Object fastDeserialize(byte[] data) throws IOException
data
- the serialized data (from fastSerialize(java.lang.Object)
) to deserializeIOException
- if deserialization failedpublic static Object fastDeserialize(byte[] data, int offset, int length) throws IOException
data
- the serialized data (from fastSerialize(java.lang.Object)
) to deserializeoffset
- the offset within byteArray of the datalength
- the length of data within byteArrayIOException
- if deserialization failedpublic static Object fastDeserialize(byte[] data, ClassLoader cl) throws IOException
data
- the serialized data (from fastSerialize(java.lang.Object)
) to deserializeIOException
- if deserialization failedpublic static Object fastDeserialize(byte[] data, int offset, int length, ClassLoader cl) throws IOException
data
- the serialized data (from fastSerialize(java.lang.Object)
) to deserializeoffset
- the offset within byteArray of the datalength
- the length of data within byteArrayIOException
- if deserialization failedpublic static void toStream(Object obj, DataOutput out) throws IOException
fromStream(java.io.DataInput)
.obj
- the object to serializeout
- the stream to serialize toIOException
- if serialization failspublic static Object fromStream(DataInput in) throws IOException
toStream(java.lang.Object, java.io.DataOutput)
. The thread context classloader
is used for deserialization.in
- the stream to deserializeIOException
- if deserialization failspublic static Object fromStream(DataInput in, ClassLoader cl) throws IOException
toStream(java.lang.Object, java.io.DataOutput)
.in
- the stream to deserializecl
- the classloader to use for deserializationIOException
- if deserialization failspublic static ProfileID readProfileID(DataInput in, ClassLoader cl) throws IOException
IOException
public static void writeProfileID(DataOutput out, ProfileID profileID) throws IOException
IOException