Modifier and Type | Class and Description |
---|---|
static class |
InstantiationUtil.ClassLoaderObjectInputStream
A custom ObjectInputStream that can load classes using a specific ClassLoader.
|
static class |
InstantiationUtil.FailureTolerantObjectInputStream
An
ObjectInputStream that ignores serialVersionUID mismatches when deserializing
objects of anonymous classes or our Scala serializer classes and also replaces occurences of
GenericData.Array (from Avro) by a dummy class so that the KryoSerializer can still be
deserialized without Avro being on the classpath. |
Modifier and Type | Method and Description |
---|---|
static void |
checkForInstantiation(Class<?> clazz)
Performs a standard check whether the class can be instantiated by
Class#newInstance() . |
static String |
checkForInstantiationError(Class<?> clazz) |
static <T extends Serializable> |
clone(T obj)
Clones the given serializable object using Java serialization.
|
static <T extends Serializable> |
clone(T obj,
ClassLoader classLoader)
Clones the given serializable object using Java serialization, using the given classloader to
resolve the cloned classes.
|
static <T extends IOReadableWritable> |
createCopyWritable(T original)
Clones the given writable using the
serialization . |
static <T> T |
deserializeFromByteArray(TypeSerializer<T> serializer,
byte[] buf) |
static <T> T |
deserializeFromByteArray(TypeSerializer<T> serializer,
T reuse,
byte[] buf) |
static <T> T |
deserializeObject(byte[] bytes,
ClassLoader cl) |
static <T> T |
deserializeObject(byte[] bytes,
ClassLoader cl,
boolean isFailureTolerant) |
static <T> T |
deserializeObject(InputStream in,
ClassLoader cl) |
static <T> T |
deserializeObject(InputStream in,
ClassLoader cl,
boolean isFailureTolerant) |
static boolean |
hasPublicNullaryConstructor(Class<?> clazz)
Checks, whether the given class has a public nullary constructor.
|
static <T> T |
instantiate(Class<T> clazz)
Creates a new instance of the given class.
|
static <T> T |
instantiate(Class<T> clazz,
Class<? super T> castTo)
Creates a new instance of the given class.
|
static <T> T |
instantiate(String className,
Class<T> targetType,
ClassLoader classLoader)
Creates a new instance of the given class name and type using the provided
ClassLoader . |
static boolean |
isNonStaticInnerClass(Class<?> clazz)
Checks, whether the class is an inner class that is not statically accessible.
|
static boolean |
isProperClass(Class<?> clazz)
Checks, whether the class is a proper class, i.e.
|
static boolean |
isPublic(Class<?> clazz)
Checks, whether the given class is public.
|
static boolean |
isSerializable(Object o) |
static <T> T |
readObjectFromConfig(Configuration config,
String key,
ClassLoader cl) |
static <T> Class<T> |
resolveClassByName(DataInputView in,
ClassLoader cl)
Loads a class by name from the given input stream and reflectively instantiates it.
|
static <T> Class<T> |
resolveClassByName(DataInputView in,
ClassLoader cl,
Class<? super T> supertype)
Loads a class by name from the given input stream and reflectively instantiates it.
|
static byte[] |
serializeObject(Object o) |
static void |
serializeObject(OutputStream out,
Object o) |
static <T> byte[] |
serializeToByteArray(TypeSerializer<T> serializer,
T record) |
static void |
writeObjectToConfig(Object o,
Configuration config,
String key) |
public static <T> T instantiate(String className, Class<T> targetType, ClassLoader classLoader) throws FlinkException
ClassLoader
.T
- type of the instantiated classclassName
- of the class to loadtargetType
- type of the instantiated classclassLoader
- to use for loading the classFlinkException
- if the class could not be foundpublic static <T> T instantiate(Class<T> clazz, Class<? super T> castTo)
T
- The generic type of the class.clazz
- The class to instantiate.castTo
- Optional parameter, specifying the class that the given class must be a
subclass off. This argument is added to prevent class cast exceptions occurring later.RuntimeException
- Thrown, if the class could not be instantiated. The exception
contains a detailed message about the reason why the instantiation failed.public static <T> T instantiate(Class<T> clazz)
T
- The generic type of the class.clazz
- The class to instantiate.RuntimeException
- Thrown, if the class could not be instantiated. The exception
contains a detailed message about the reason why the instantiation failed.public static boolean hasPublicNullaryConstructor(Class<?> clazz)
clazz
- The class to check.public static boolean isPublic(Class<?> clazz)
clazz
- The class to check.public static boolean isProperClass(Class<?> clazz)
clazz
- The class to check.public static boolean isNonStaticInnerClass(Class<?> clazz)
clazz
- The class to check.public static void checkForInstantiation(Class<?> clazz)
Class#newInstance()
.clazz
- The class to check.RuntimeException
- Thrown, if the class cannot be instantiated by Class#newInstance()
.public static <T> T readObjectFromConfig(Configuration config, String key, ClassLoader cl) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
public static void writeObjectToConfig(Object o, Configuration config, String key) throws IOException
IOException
public static <T> byte[] serializeToByteArray(TypeSerializer<T> serializer, T record) throws IOException
IOException
public static <T> T deserializeFromByteArray(TypeSerializer<T> serializer, byte[] buf) throws IOException
IOException
public static <T> T deserializeFromByteArray(TypeSerializer<T> serializer, T reuse, byte[] buf) throws IOException
IOException
public static <T> T deserializeObject(byte[] bytes, ClassLoader cl) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
public static <T> T deserializeObject(InputStream in, ClassLoader cl) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
public static <T> T deserializeObject(byte[] bytes, ClassLoader cl, boolean isFailureTolerant) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
public static <T> T deserializeObject(InputStream in, ClassLoader cl, boolean isFailureTolerant) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
public static byte[] serializeObject(Object o) throws IOException
IOException
public static void serializeObject(OutputStream out, Object o) throws IOException
IOException
public static boolean isSerializable(Object o)
public static <T extends Serializable> T clone(T obj) throws IOException, ClassNotFoundException
T
- Type of the object to cloneobj
- Object to cloneIOException
- Thrown if the serialization or deserialization process fails.ClassNotFoundException
- Thrown if any of the classes referenced by the object cannot
be resolved during deserialization.public static <T extends Serializable> T clone(T obj, ClassLoader classLoader) throws IOException, ClassNotFoundException
T
- Type of the object to cloneobj
- Object to cloneclassLoader
- The classloader to resolve the classes during deserialization.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.public static <T extends IOReadableWritable> T createCopyWritable(T original) throws IOException
serialization
.T
- Type of the object to cloneoriginal
- Object to cloneIOException
- Thrown is the serialization fails.public static <T> Class<T> resolveClassByName(DataInputView in, ClassLoader cl) throws IOException
This method will use DataInput.readUTF()
to read the class name, and then
attempt to load the class from the given ClassLoader.
in
- The stream to read the class name from.cl
- The class loader to resolve the class.IOException
- Thrown, if the class name could not be read, the class could not be
found.public static <T> Class<T> resolveClassByName(DataInputView in, ClassLoader cl, Class<? super T> supertype) throws IOException
This method will use DataInput.readUTF()
to read the class name, and then
attempt to load the class from the given ClassLoader.
The resolved class is checked to be equal to or a subtype of the given supertype class.
in
- The stream to read the class name from.cl
- The class loader to resolve the class.supertype
- A class that the resolved class must extend.IOException
- Thrown, if the class name could not be read, the class could not be
found, or the class is not a subtype of the given supertype class.Copyright © 2014–2022 The Apache Software Foundation. All rights reserved.