Class InstantiationUtil
- java.lang.Object
-
- org.apache.flink.cdc.common.utils.InstantiationUtil
-
public class InstantiationUtil extends Object
Utility class to create instances from class objects.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classInstantiationUtil.ClassLoaderObjectInputStreamA custom ObjectInputStream that can load classes using a specific ClassLoader.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Serializable>
Tclone(T obj)Clones the given serializable object using Java serialization.static <T extends Serializable>
Tclone(T obj, ClassLoader classLoader)Clones the given serializable object using Java serialization, using the given classloader to resolve the cloned classes.static <T> TdeserializeFromByteArray(org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer, byte[] buf)static <T> TdeserializeFromByteArray(org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer, T reuse, byte[] buf)static <T> TdeserializeObject(byte[] bytes, ClassLoader cl)static <T> TdeserializeObject(InputStream in, ClassLoader cl)static booleanisSerializable(Object o)static voidserializeObject(OutputStream out, Object o)static byte[]serializeObject(Object o)static byte[]serializeObjectAndCompress(Object o)static <T> byte[]serializeToByteArray(org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer, T record)
-
-
-
Method Detail
-
serializeObject
public static byte[] serializeObject(Object o) throws IOException
- Throws:
IOException
-
serializeObject
public static void serializeObject(OutputStream out, Object o) throws IOException
- Throws:
IOException
-
serializeObjectAndCompress
public static byte[] serializeObjectAndCompress(Object o) throws IOException
- Throws:
IOException
-
isSerializable
public static boolean isSerializable(Object o)
-
serializeToByteArray
public static <T> byte[] serializeToByteArray(org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer, T record) throws IOException- Throws:
IOException
-
deserializeFromByteArray
public static <T> T deserializeFromByteArray(org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer, byte[] buf) throws IOException- Throws:
IOException
-
deserializeFromByteArray
public static <T> T deserializeFromByteArray(org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer, T reuse, byte[] buf) throws IOException- Throws:
IOException
-
deserializeObject
public static <T> T deserializeObject(byte[] bytes, ClassLoader cl) throws IOException, ClassNotFoundException- Throws:
IOExceptionClassNotFoundException
-
deserializeObject
public static <T> T deserializeObject(InputStream in, ClassLoader cl) throws IOException, ClassNotFoundException
- Throws:
IOExceptionClassNotFoundException
-
clone
public static <T extends Serializable> T clone(T obj) throws IOException, ClassNotFoundException
Clones the given serializable object using Java serialization.- Type Parameters:
T- Type of the object to clone- Parameters:
obj- Object to clone- Returns:
- The cloned object
- Throws:
IOException- Thrown if the serialization or deserialization process fails.ClassNotFoundException- Thrown if any of the classes referenced by the object cannot be resolved during deserialization.
-
clone
public static <T extends Serializable> T clone(T obj, ClassLoader classLoader) throws IOException, ClassNotFoundException
Clones the given serializable object using Java serialization, using the given classloader to resolve the cloned classes.- Type Parameters:
T- Type of the object to clone- Parameters:
obj- Object to cloneclassLoader- The classloader to resolve the classes during deserialization.- Returns:
- Cloned object
- Throws:
IOException- Thrown if the serialization or deserialization process fails.ClassNotFoundException- Thrown if any of the classes referenced by the object cannot be resolved during deserialization.
-
-