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 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> 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 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
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 byte[] serializeObject(Object o) throws IOException
IOException
public static <T extends Serializable> T clone(T obj) throws IOException, ClassNotFoundException
T
- Type of the object to cloneobj
- Object to cloneIOException
ClassNotFoundException
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
ClassNotFoundException
Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.