public final class InstantiationUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
InstantiationUtil.ClassLoaderObjectInputStream
A custom ObjectInputStream that can also load user-code using a
user-code ClassLoader.
|
| 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> T |
deserializeFromByteArray(TypeSerializer<T> serializer,
byte[] buf) |
static <T> T |
deserializeObject(byte[] bytes,
ClassLoader cl) |
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 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 <T> T |
readObjectFromConfig(Configuration config,
String key,
ClassLoader cl) |
static byte[] |
serializeObject(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(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
IOExceptionClassNotFoundExceptionpublic static void writeObjectToConfig(Object o, Configuration config, String key) throws IOException
IOExceptionpublic static <T> byte[] serializeToByteArray(TypeSerializer<T> serializer, T record) throws IOException
IOExceptionpublic static <T> T deserializeFromByteArray(TypeSerializer<T> serializer, byte[] buf) throws IOException
IOExceptionpublic static <T> T deserializeObject(byte[] bytes,
ClassLoader cl)
throws IOException,
ClassNotFoundException
IOExceptionClassNotFoundExceptionpublic static byte[] serializeObject(Object o) throws IOException
IOExceptionCopyright © 2014–2016 The Apache Software Foundation. All rights reserved.